Fixed and Random and Some of Both
2025-07-28
xt commandsIn Statas language, \texttt{xt} is the way that one naturally refers to CSTS/TSCS data. Consider NT observations on some random variable y_{it} where i \in N and t \in T. The TSCS/CSTS commands almost always have this prefix. \begin{itemize} - \texttt{xtset}: Declaring data - \texttt{xtdes}: Describing data structure - \texttt{xtsum}: Summarizing data - \texttt{xttab}: Summarizing categorical data. - \texttt{xttrans}: Transition matrix for data. - \texttt{xtline}: Line graphs for data.
Given two-dimensional data, how should we break it down? The most common method is unit-averages; we break each unit’s time series on each element into deviations from their own mean. This is called the within transform. The between portion represents deviations between the unit’s mean and the overall mean. Stationarity considerations are generically implicit.
Let A be a variance/covariance matrix across panels and B be the same matrix for a given panel. This is a fairly general way to conceive of a panel data problem.
The homoscedastic case is described by \sigma^2 I.
The [unit] heteroscedastic case is described, generally, by \sigma^{2}_{i} I_{N} \otimes I_{t} \left(\begin{array}{cccc}\sigma^{2}_{1}I_{T} & 0 & 0 & 0 \\ 0 & \sigma^{2}_{2}I_{T} & 0 & 0 \\ 0 & 0 & \ddots & 0 \\ 0 & 0 & 0 & \sigma^{2}_{N}I_{T} \end{array}\right) The ultimate result will be of dimension NT\times NT. The first T entries will be \sigma^{2}_{1}, entries T+1 to 2T will be \sigma^{2}_{2} \ldots and the entries (N-1)T + 1 to NT will be \sigma^{2}_{N}. If we believed that the heteroscedasticity arose from time points rather than units, replace N with T and vice versa; i becomes t.
\Phi = \sigma^{2}\Psi = \sigma^{2}_{e} \left(\begin{array}{ccccc}1 & \rho_{1} & \rho_{2} & \ldots & \rho_{T-1} \\ \rho_1 & 1 & \rho_1 & \ldots & \rho_{T-2} \\ \rho_{2} & \rho_1 & 1 & \ldots & \rho_{T-3} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ \rho_{T-1} & \rho_{T-2} & \rho_{T-3} & \ldots & 1 \end{array}\right)
given that e_{t} = \rho e_{t-1} + \nu_{t}. A Toeplitz form….
This allows us to calculate the variance of e using results from basic statistics, i.e. Var(e_{t}) = \rho^{2}Var(e_{t-1}) + Var(\nu). If the variance is stationary, we can rewrite,
\sigma^{2}_{e} = \frac{\sigma^{2}_{\nu}}{1 - \rho^{2}}
When discussing heteroscedasticity, we notice that the off-diagonal elements are all zeroes. This is the assumption of no correlation among [somehow] adjacent elements. The somehow takes two forms: (1) spatial and (2) temporal. Just as before where time-induced heteroscedasticity simply involved interchanging N and T and i and t; the same idea prevails here.
In a now-classic paper, Aitken generalized the Gauss-Markov theorem to the class of Generalized Least Squares estimators. It is important to note that these are GLS and not FGLS estimators. What is the difference? The two GLS estimators considered by Stimson are not strictly speaking GLS.
Definition: \hat{\beta}_{GLS} = (\mathbf{X}^{\prime}\Omega^{-1}\mathbf{X})^{-1}\mathbf{X}^{\prime}\Omega^{-1}\mathbf{y}
Properties:
We need to estimate things to replace unknown covariance structures and coverage will depend on properties of the estimators of these covariances. Consistent estimators will work but there is euphemistically considerable variation in the class of consistent estimators. Contrasting the Beck and Katz/White approach with the GLS approach is a valid difference in philosophies. NB: We will return to this when we look at Hausman because this is the essential issue.
Beck and Katz take a different tack to the general data types in common use (long T). The basic idea is to generate estimates using OLS because GLS can be quite bad. .red[What do we need to be able to do this?]
Every \texttt{Stata} user is familiar with this, it seems. Though not developed by Stata (but Hardin, a student of Huber), the two are synonymous. What would these look like in an application?
Two significant options of note
Most discussions of panel data estimators draw on a fixed versus random effects distinction. The subtle distinction is important but perhaps overstated.
Let’s construct a general model: y_{it} = \alpha_{it} + X_{it}\beta_{it} + \epsilon_{it}
\alpha_{i} \sim [ \alpha , \sigma^{2}_{\alpha} ]
\epsilon_{it} \sim [0 , \sigma^{2}_{\epsilon}]
A brief simulation.
\sum_{i=1}^{N} \sum_{t=1}^{T} (x_{it} - \overline{x})^{2} = \sum_{i=1}^{N} \sum_{t=1}^{T} x_{it}^{2} - NT\overline{x}^{2}
\sum_{i=1}^{N} \sum_{t=1}^{T} x_{it}^{2} - T_{i} \overline{x}_{i} + T_{i}\overline{x}_{i} - NT\overline{x}^{2}
\sum_{i=1}^{N} \underbrace{\sum_{t=1}^{T} (x_{it} - \overline{x}_{i})^{2}}_{W_{i}} + \underbrace{\sum_{i=1}^{N} T_{i}(\overline{x}_{i} - \overline{x})^{2}}_{B_{T}}
For total pooling, we can F-test \frac{3 - 1}{1}. This is the least and most restricted sets of models. If we can reject this, pooling is (perhaps) justified? Now let’s construct some others. Suppose we reject total pooling. Is it intercepts, slopes, or both? Imposing a slope restriction gives us 2, the F we want is \frac{2-1}{1}. What do we get from \frac{3-2}{2}? NB: It’s conditional. We can also do this with time. This is a good starting point, but it is not as clean as we might like.
\hat{\beta}_{OLS} = [S^{t}_{xx}]^{-1} S^{t}_{xy} \hat{\beta}_{OLS} = [S^{w}_{xx} + S^{b}_{xx}]^{-1} (S^{w}_{xy} + S^{b}_{xy}) \hat{\beta}_{OLS} = [S^{w}_{xx} + S^{b}_{xx}]^{-1}S^{w}_{xy} + [S^{w}_{xx} + S^{b}_{xx}]^{-1}S^{b}_{xy}
Let F^{w} = [S^{w}_{xx} + S^{b}_{xx}]^{-1}S^{w}_{xx} \rightarrow F^{b} = I - F^{w} = [S^{w}_{xx} + S^{b}_{xx}]^{-1}S^{b}_{xx}.
My claim is that \hat{\beta}_{OLS} = F^{w}\beta^{w} + F^{b}\beta^{b}.
\hat{\beta}_{OLS} = [S^{w}_{xx} + S^{b}_{xx}]^{-1}\underbrace{S^{w}_{xx}[S_{xx}^{w}]^{-1}}_{I}S_{xy}^{w} + [S^{w}_{xx} + S^{b}_{xx}]^{-1}\underbrace{S^{b}_{xx}[S_{xx}^{b}]^{-1}}_{I}S_{xy}^{b} \hat{\beta}_{OLS} = [S^{w}_{xx} + S^{b}_{xx}]^{-1}S_{xy}^{w} + [S^{w}_{xx} + S^{b}_{xx}]^{-1}S_{xy}^{b}
The basic idea is that the fixed effects estimator is consistent but potentially inefficient. The random effects estimator is only consistent under the null. We can leverage this to form a test in the Hausman family using the result proved in the paper. This is implemented in Stata using model storage capabilities.
The basic idea behind Mundlak’s paper is that the fixed versus random effects debate is ill conceived. Moreover, there is a right model. Why and how?
Estimate a variant of the Mundlak model that accommodates all the concerns.
y_{it} = \beta_{0} + \beta_{1W}(x_{it} - \overline{x}_{i}) + \beta_{2B}\overline{x}_{i} + \beta_{3}z_{i} + ( \nu_{i} + \epsilon_{it})
Define \Delta to be a difference operator so that we can define \Delta X = X_{it} - X_{i,t-1}
\Delta y = y_{it} - y_{i,t-1}
Observation: N(T-1) observations if T_{i} \geq 2\;\;\; \forall i. Equality case is interesting. The first-difference estimator is then: \Delta y = \beta(\Delta X) + \epsilon_{it}
And an OLS estimator would simply look like: \hat{\beta} = (\Delta X^{\prime}\Delta X{})^{-1} (\Delta X^{\prime} \Delta y) NB: For T=2 show that FE is FD.
Either transformation removes heterogeneity. The difference is that the two estimators operate at different orders of integration. The difference is not purely convenience; there is substance to this and theory can help. At the same time, the statistics matter.
The fixed effect model is entirely conditional on the sample. If we do not know a unit fixed effect, the predictions are undefined. The random effects model can sample from the distribution of random effects.
\texttt{xtreg}: contains five estimators. For now, we will skip (\texttt{pa}).
\texttt{be}: the between effects estimator. \overline{y}_{i} = \overline{x}_{i} + \epsilon_{i}
\texttt{fe}: the fixed effects or within estimator. y^{C_{i}} = \mathbf{X}^{C_{i}} + \epsilon_{it}
\texttt{mle}: the maximum likelihood random effects estimator.
That weight is not in any sense optimally determined, it is a function of the relative ratio of the two quantities (all variance counts the same). As Hsiao (p. 37) points out that the random effects estimator is often known as a quasi-demeaning estimator. This is because it is a partial within transformation.
We will start with the model we defined as random effects before. We defined random effects \alpha_{i} \bot X_{it}: \alpha_{i} \sim [\alpha , \sigma^{2}_{\alpha}] \; \; \epsilon_{it} \sim [0 , \sigma^{2}_{\epsilon}]. Consider \nu_{it} = \alpha_{i} + \epsilon_{it}.
For a single cross-section (remembering the Kronecker product will help us here) \mathbb{E}(\nu_{it}\nu_{it}^{\prime}) = \sigma^{2}_{\epsilon}\mathbf{I_{T}} + \sigma_{\alpha}^{2}\mathbf{1}_{T} = \Omega The inverse is given by \Omega^{-1} = \frac{1}{\sigma^{2}_{\epsilon}}\left[\mathbf{I_{T}} - \frac{\sigma^{2}_{\alpha}}{\sigma_{\epsilon}^{2} + T\sigma^{2}_{\alpha}}\mathbf{1}_{T} \right]
We can also estimate this by using ordinary least squares applied to transformed data. The quasi-demeaning can be done in a first-stage with OLS estimates on the quasi-demeaned data. Recall the pooled regression uses no transformation. The within estimator uses complete demeaning. The random effects estimator is somewhere in between.
Breusch and Pagan (modified by Baltagi and Li) have developed a Lagrange multiplier test of whether or not the random effects have a variance. The test statistic is defined as:
LM = \frac{NT}{2(T-1)}\left[\frac{\sum_{N} \left( \sum_{T} \epsilon_{it} \right)^{2} } {\sum_{N} \sum_{T} \epsilon_{it}^{2} } - 1 \right] \sim \chi^{2}_{1}
. xtreg growth lagg opengdp openex openimp leftc central inter, re
Random-effects GLS regression Number of obs = 240
Group variable (i): country Number of groups = 16
-----------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+---------------------------------------------------------------
lagg1 | .151848 .0865508 1.75 0.079 -.0177884 .3214843
opengdp | .0082889 .0010012 8.28 0.000 .0063267 .0102511
openex | .0019834 .0005903 3.36 0.001 .0008263 .0031404
openimp | -.0047988 .0010474 -4.58 0.000 -.0068518 -.0027459
leftc | -.0268801 .0108211 -2.48 0.013 -.048089 -.0056711
central | -.7428119 .2547157 -2.92 0.004 -1.242045 -.2435784
inter | .0138935 .0041671 3.33 0.001 .0057261 .0220609
_cons | 3.607517 .571187 6.32 0.000 2.488011 4.727023
-------------+---------------------------------------------------------------
sigma_u | .36517121
sigma_e | 2.0094449
rho | .03196908 (fraction of variance due to u_i)
-----------------------------------------------------------------------------
. xtreg growth lagg1 opengdp, fe
Fixed-effects (within) regression Number of obs = 240
Group variable (i): country Number of groups = 16
R-sq: within = 0.2562 Obs per group: min = 15
between = 0.0031 avg = 15.0
overall = 0.1563 max = 15
F(2,222) = 38.23
corr(u_i, Xb) = -0.3888 Prob > F = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .2647972 .0851979 3.11 0.002 .0968971 .4326972
opengdp | .0094949 .0011229 8.46 0.000 .007282 .0117078
_cons | .5289261 .3719065 1.42 0.156 -.2039929 1.261845
-------------+----------------------------------------------------------------
sigma_u | 1.142546
sigma_e | 2.0889953
rho | .23025918 (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(15, 222) = 3.55 Prob > F = 0.0000
. reg Cgrowth Clagg1 Copengdp
Source | SS df MS Number of obs = 240
-------------+------------------------------ F( 2, 237) = 40.81
Model | 333.650655 2 166.825327 Prob > F = 0.0000
Residual | 968.786108 237 4.0877051 R-squared = 0.2562
-------------+------------------------------ Adj R-squared = 0.2499
Total | 1302.43676 239 5.4495262 Root MSE = 2.0218
-----------------------------------------------------------------------------
Cgrowth | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+---------------------------------------------------------------
Clagg1 | .2647972 .0824577 3.21 0.002 .1023536 .4272408
Copengdp | .0094949 .0010868 8.74 0.000 .0073539 .0116359
_cons | 1.30e-08 .1305071 0.00 1.000 -.2571021 .2571021
------------------------------------------------------------------------------
. by country: egen gmean = mean(growth)
. by country: egen glmean = mean(lagg1)
. by country: egen opengdpmean = mean(opengdp)
. gen yhatb = _b[_cons] + _b[lagg1]*glmean + _b[opengdp]*opengdpmean
. reg gmean yhatb
Source | SS df MS Number of obs = 240
-------------+------------------------------ F( 1, 238) = 0.75
Model | .445360906 1 .445360906 Prob > F = 0.3868
Residual | 140.975583 238 .592334381 R-squared = 0.0031
-------------+------------------------------ Adj R-squared = -0.0010
Total | 141.420943 239 .591719429 Root MSE = .76963
------------------------------------------------------------------------------
gmean | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yhatb | -.0570801 .0658282 -0.87 0.387 -.1867605 .0726003
_cons | 3.185291 .2044862 15.58 0.000 2.782457 3.588125
------------------------------------------------------------------------------
gen yhatT = _b[_cons] + _b[lagg1]*lagg1 + _b[opengdp]*opengdp
. fit growth yhatT
Source | SS df MS Number of obs = 240
-------------+------------------------------ F( 1, 238) = 44.11
Model | 225.744206 1 225.744206 Prob > F = 0.0000
Residual | 1218.11349 238 5.11812392 R-squared = 0.1563
-------------+------------------------------ Adj R-squared = 0.1528
Total | 1443.8577 239 6.0412456 Root MSE = 2.2623
------------------------------------------------------------------------------
growth | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yhatT | .6927893 .1043154 6.64 0.000 .48729 .8982887
_cons | .9257153 .3465985 2.67 0.008 .2429227 1.608508
------------------------------------------------------------------------------
Extending this basic logic will hold for all estimators. Basically, think about them as projecting any given model result to the centered data, to group means, and to all data.
We saw fixed and random effects. The basic idea generalizes to regression coefficients on variables that are not unit-specific factors/indicators.
y_{it} = \alpha + (\overline{\beta} + \mu_{i})X_{it} + \epsilon_{it} \mathbb{E}[\mu_{i}] = 0; \mathbb{E}[\mu_{i} X_{it}]=0 \mathbb{E}[\alpha_{i}\alpha_{j}] = \begin{cases} \Delta & \text{if } i = j \\ 0 & \text{if } i \neq j \end{cases}
Hsiao and Pesaran (2004, IZA DP 136) show that the GLS estimator is a matrix weighted average of the OLS estimator applied to each unit separately with weights inversely proportional to the covariance matrix for the unit.
\texttt{xtrc} estimates the Swamy random coefficients model and provides us with a test statistic of parameter constancy. If the statistic is significantly different from zero, parameter constancy is rejected. Option \texttt{betas} gives us the unit-specifics. We have \texttt{vce} options here also.
Note, as with many \texttt{xt} commands, the jackknife is unit-based.
Stata has a mixed effects module that we can use for some things we have already seen and for extensions. I should say in passing that this also works for dimensions with nesting properties, though we are looking at two-dimensional data structures.
. sum
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
year | 240 1977 4.329523 1970 1984
country | 240 8.5 4.619406 1 16
growth | 240 3.013292 2.457895 -3.6 9.8
lagg1 | 240 3.119855 1.652682 -2.40641 6.683519
opengdp | 240 174.6452 146.2456 -32.1 736.02
----------+--------------------------------------------------------
openex | 240 489.7662 420.4374 30.94 2879.2
openimp | 240 482.8254 267.6722 64.96 1415.2
leftc | 240 34.79583 39.56008 0 100
central | 240 2.02421 .9593759 .4054115 3.618419
inter | 240 91.33376 117.5622 0 361.8419
. xtreg growth lagg1 opengdp openimp openex leftc, re
Random-effects GLS regression Number of obs = 240
Group variable (i): country Number of groups = 16
R-sq: within = 0.2960 Obs per group: min = 15
between = 0.2038 avg = 15.0
overall = 0.2811 max = 15
Random effects u_i ~ Gaussian Wald chi2(5) = 92.41
corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .2194248 .0875581 2.51 0.012 .0478142 .3910355
opengdp | .0077965 .0009824 7.94 0.000 .005871 .0097219
openimp | -.0053695 .0009868 -5.44 0.000 -.0073035 -.0034355
openex | .0019647 .0006047 3.25 0.001 .0007796 .0031498
leftc | .0030365 .0036142 0.84 0.401 -.0040472 .0101202
_cons | 2.491734 .4633904 5.38 0.000 1.583505 3.399962
-------------+----------------------------------------------------------------
sigma_u | .21759529
sigma_e | 2.0364407
rho | .01128821 (fraction of variance due to u_i)
------------------------------------------------------------------------------
. xtreg growth lagg1 opengdp openimp openex leftc, mle
Random-effects ML regression Number of obs = 240
Group variable (i): country Number of groups = 16
Random effects u_i ~ Gaussian Obs per group: min = 15
LR chi2(5) = 81.33
Log likelihood = -514.4714 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .1873509 .0881362 2.13 0.034 .014607 .3600947
opengdp | .0077706 .0009913 7.84 0.000 .0058276 .0097136
openimp | -.0055243 .0010506 -5.26 0.000 -.0075835 -.0034651
openex | .0020447 .0005936 3.44 0.001 .0008812 .0032082
leftc | .0044378 .0039745 1.12 0.264 -.0033521 .0122277
_cons | 2.583146 .5204807 4.96 0.000 1.563022 3.603269
-------------+----------------------------------------------------------------
/sigma_u | .5100119 .1962033 .2399497 1.084028
/sigma_e | 2.018389 .0957214 1.839233 2.214995
rho | .0600166 .0445522 .0110832 .2056057
------------------------------------------------------------------------------
Likelihood-ratio test of sigma_u=0: chibar2(01)= 3.56 Prob>=chibar2 = 0.030
. xtmixed growth lagg1 opengdp openimp openex leftc || R.country, mle
Mixed-effects ML regression Number of obs = 240
Group variable: _all Number of groups = 1
Wald chi2(5) = 97.44
Log likelihood = -514.4714 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .1873501 .0859494 2.18 0.029 .0188925 .3558078
opengdp | .0077706 .0009911 7.84 0.000 .0058281 .009713
openimp | -.0055243 .0010452 -5.29 0.000 -.0075729 -.0034757
openex | .0020447 .0005915 3.46 0.001 .0008854 .0032039
leftc | .0044378 .0038479 1.15 0.249 -.003104 .0119796
_cons | 2.583148 .5173579 4.99 0.000 1.569145 3.597151
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
_all: Identity |
sd(R.country) | .5100191 .1962046 .2399545 1.084037
-----------------------------+------------------------------------------------
sd(Residual) | 2.018388 .0957229 1.83923 2.214997
------------------------------------------------------------------------------
LR test vs. linear regression: chibar2(01) = 3.56 Prob >= chibar2 = 0.0296
For virtually all Stata commands, we can acquire multiple variance/covariance matrices of the parameters.
Will allow us to do tons of things. In particular, we can play with the residual correlation matrix using the option \texttt{residuals}. One can recreate virtually everything that we have seen so far this way. The remaining task for you in the lab is to figure out what all you can make it do.
Mixed effects models will allow us to estimate many interesting models for data.
For the simple random effects estimator, there are two ways to do it via ML.
. xtreg growth lagg1 opengdp openimp openex leftc, mle
LR chi2(5) = 81.33
Log likelihood = -514.4714 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .1873509 .0881362 2.13 0.034 .014607 .3600947
opengdp | .0077706 .0009913 7.84 0.000 .0058276 .0097136
openimp | -.0055243 .0010506 -5.26 0.000 -.0075835 -.0034651
openex | .0020447 .0005936 3.44 0.001 .0008812 .0032082
leftc | .0044378 .0039745 1.12 0.264 -.0033521 .0122277
_cons | 2.583146 .5204807 4.96 0.000 1.563022 3.603269
-------------+----------------------------------------------------------------
/sigma_u | .5100119 .1962033 .2399497 1.084028
/sigma_e | 2.018389 .0957214 1.839233 2.214995
rho | .0600166 .0445522 .0110832 .2056057
------------------------------------------------------------------------------
Likelihood-ratio test of sigma_u=0: chibar2(01)= 3.56 Prob>=chibar2 = 0.030
. xtmixed growth lagg1 opengdp openimp openex leftc || _all: R.country, mle
Wald chi2(5) = 97.44
Log likelihood = -514.4714 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .1873501 .0859494 2.18 0.029 .0188925 .3558078
opengdp | .0077706 .0009911 7.84 0.000 .0058281 .009713
openimp | -.0055243 .0010452 -5.29 0.000 -.0075729 -.0034757
openex | .0020447 .0005915 3.46 0.001 .0008854 .0032039
leftc | .0044378 .0038479 1.15 0.249 -.003104 .0119796
_cons | 2.583148 .5173579 4.99 0.000 1.569145 3.597151
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
_all: Identity |
sd(R.country) | .5100191 .1962046 .2399545 1.084037
-----------------------------+------------------------------------------------
sd(Residual) | 2.018388 .0957229 1.83923 2.214997
------------------------------------------------------------------------------
LR test vs. linear regression: chibar2(01) = 3.56 Prob >= chibar2 = 0.0296
Mixed-effects ML regression Number of obs = 240
Group variable: _all Number of groups = 1
Obs per group: min = 240
avg = 240.0
max = 240
Wald chi2(5) = 7.18
Log likelihood = -503.45468 Prob > chi2 = 0.2076
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .0059048 .1296512 0.05 0.964 -.2482069 .2600164
opengdp | .0001904 .0016087 0.12 0.906 -.0029626 .0033433
openimp | -.0030722 .0015617 -1.97 0.049 -.006133 -.0000114
openex | .002307 .0010185 2.27 0.024 .0003108 .0043032
leftc | .0048234 .0036133 1.33 0.182 -.0022585 .0119053
_cons | 3.147245 .7630121 4.12 0.000 1.651768 4.642721
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
_all: Identity |
sd(R.country) | .6667379 .1900389 .3813634 1.165658
-----------------------------+------------------------------------------------
_all: Identity |
sd(R.year) | 1.554459 .4033566 .9347738 2.58495
-----------------------------+------------------------------------------------
sd(Residual) | 1.752177 .0885389 1.586961 1.934595
------------------------------------------------------------------------------
LR test vs. linear regression: chi2(2) = 25.59 Prob > chi2 = 0.0000
Note: LR test is conservative and provided only for reference
. estimates store MLEtwowayRE
. lrtest MLEtwowayRE MLEunitRE
Likelihood-ratio test LR chibar2(01) = 22.03
(Assumption: MLEunitRE nested in MLEtwowayRE) Prob > chibar2 = 0.0000
. qui xtmixed growth lagg1 opengdp openimp openex leftc || _all: R.year, mle
. lrtest MLEtwowayRE .
Likelihood-ratio test LR chibar2(01) = 10.04
(Assumption: . nested in MLEtwowayRE) Prob > chibar2 = 0.0008
. xtmixed growth lagg1 opengdp openimp openex leftc || country: leftc, covariance(unstructured)
Performing EM optimization:
Performing gradient-based optimization:
Iteration 0: log restricted-likelihood = -540.17955
Iteration 1: log restricted-likelihood = -540.15493
Iteration 2: log restricted-likelihood = -540.15472
Iteration 3: log restricted-likelihood = -540.15472
Computing standard errors:
Mixed-effects REML regression Number of obs = 240
Group variable: country Number of groups = 16
Obs per group: min = 15
avg = 15.0
max = 15
Wald chi2(5) = 95.70
Log restricted-likelihood = -540.15472 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
growth | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
lagg1 | .170562 .0869219 1.96 0.050 .0001982 .3409259
opengdp | .0078608 .0010053 7.82 0.000 .0058905 .0098312
openimp | -.0055371 .0010763 -5.14 0.000 -.0076465 -.0034277
openex | .0020745 .0005967 3.48 0.001 .0009051 .0032439
leftc | .0039332 .0046265 0.85 0.395 -.0051346 .013001
_cons | 2.570449 .5444497 4.72 0.000 1.503347 3.637551
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
-----------------------------+------------------------------------------------
country: Unstructured |
sd(leftc) | .0089451 .0078813 .0015908 .0502989
sd(_cons) | .6566839 .2658791 .2969756 1.452085
corr(leftc,_cons) | -.6168731 .5300418 -.9835763 .7429732
-----------------------------+------------------------------------------------
sd(Residual) | 2.022226 .098202 1.83863 2.224156
------------------------------------------------------------------------------
LR test vs. linear regression: chi2(3) = 5.40 Prob > chi2 = 0.1445
Note: LR test is conservative and provided only for reference
. * The coefficient is insignificant as is the randomness
. estat recovariance
Random-effects covariance matrix for level country
| leftc _cons
-------------+----------------------
leftc | .00008
_cons | -.0036236 .4312338
. capture drop u1 u2
. predict u*, reffects
. by country, sort: sum u*
---------------------------------------------------------------------------------------------------------------
-> country = AUL
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
u1 | 15 -.0006591 0 -.0006591 -.0006591
u2 | 15 .1237475 0 .1237475 .1237475
-> country = AUS
u1 | 15 .0005591 0 .0005591 .0005591
u2 | 15 .0125652 0 .0125652 .0125652
-> country = BEL
u1 | 15 -.0000316 0 -.0000316 -.0000316
u2 | 15 -.0002924 0 -.0002924 -.0002924
-> country = CAN
u1 | 15 -.0035756 0 -.0035756 -.0035756
u2 | 15 .4255248 0 .4255248 .4255248
-> country = DEN
u1 | 15 .0019625 0 .0019625 .0019625
u2 | 15 -.462575 0 -.462575 -.462575
-> country = FIN
u1 | 15 .003543 0 .003543 .003543
u2 | 15 .1606634 0 .1606634 .1606634
-> country = FRA
u1 | 15 -.0083416 0 -.0083416 -.0083416
u2 | 15 .3128709 0 .3128709 .3128709
-> country = GER
u1 | 15 .0011514 0 .0011514 .0011514
u2 | 15 -.3119804 0 -.3119804 -.3119804
-> country = IRE
u1 | 15 -.0021854 0 -.0021854 -.0021854
u2 | 15 .3908045 0 .3908045 .3908045
-> country = ITA
u1 | 15 .0002358 0 .0002358 .0002358
u2 | 15 -.1705837 0 -.1705837 -.1705837
-> country = JAP
u1 | 15 -.0090248 0 -.0090248 -.0090248
u2 | 15 1.074025 0 1.074025 1.074025
-> country = NET
u1 | 15 .0031352 0 .0031352 .0031352
u2 | 15 -.2520462 0 -.2520462 -.2520462
-> country = NOR
u1 | 15 .0088704 0 .0088704 .0088704
u2 | 15 .0223926 0 .0223926 .0223926
-> country = SWE
u1 | 15 .002398 0 .002398 .002398
u2 | 15 -.5351107 0 -.5351107 -.5351107
-> country = UK
u1 | 15 .000085 0 .000085 .000085
u2 | 15 -.5665398 0 -.5665398 -.5665398
-> country = USA
u1 | 15 .0018777 0 .0018777 .0018777
u2 | 15 -.2234658 0 -.2234658 -.2234658
A Plot
Survey of papers using TSCS data and methods(?)
Vast majority do nothing about space or time.
Does it matter?
Table 3
Table 4
What do we do? Raise the bar for positive findings and look at multiple models trying to tease out the role of particular assumptions as necessary and/or sufficient for results.
. xttest0
Breusch and Pagan Lagrangian multiplier test for random effects:
growth[country,t] = Xb + u[country] + e[country,t]
Estimated results:
| Var sd = sqrt(Var)
---------+-----------------------------
growth | 6.041246 2.457895
e | 4.147091 2.036441
u | .0473477 .2175953
Test: Var(u) = 0
chi2(1) = 4.39
Prob > chi2 = 0.0361
. xttest1
Tests for the error component model:
growth[country,t] = Xb + u[country] + v[country,t]
v[country,t] = rho v[country,(t-1)] + e[country,t]
Estimated results:
Var sd = sqrt(Var)
---------+-----------------------------
growth | 6.041246 2.457895
e | 4.037869 2.0094449
u | .13335 .36517121
Tests:
Random Effects, Two Sided:
LM(Var(u)=0) = 1.00 Pr>chi2(1) = 0.3174
ALM(Var(u)=0) = 0.54 Pr>chi2(1) = 0.4610
Random Effects, One Sided:
LM(Var(u)=0) = 1.00 Pr>N(0,1) = 0.1587
ALM(Var(u)=0) = 0.74 Pr>N(0,1) = 0.2305
Serial Correlation:
LM(rho=0) = 0.74 Pr>chi2(1) = 0.3906
ALM(rho=0) = 0.28 Pr>chi2(1) = 0.5961
Joint Test:
LM(Var(u)=0,rho=0) = 1.28 Pr>chi2(2) = 0.5271
* We cannot reject the null hypothesis of no variation in the random effects.
Also no evidence of serial correlation.
Remember, with the lagged endogenous variable on the right hand side,
the random effects are included if they are there.
After \texttt{fe} or \texttt{xtgls}, we have two tests pre-programmed.
Wooldridge presents a test for serial correlation.
How do we test for cross-sectional dependence?
Driscoll and Kraay (1998) describe a robust covariance matrix estimator for pooled and fixed effects regression models that contain a large time dimension. The approach is robust to heteroscedasticity, autocorrelation, and spatial correlation.
There are limitation imposed by what people have programmed in terms of regression diagnostics. However, if we can fit the same model by OLS, we can use standard regression diagnostics post-estimation to avoid calculating the diagnostics by hand. Many diagnostics are pre-programmed.
avplot: added-variable plotLevin-Lin-Chu ( \texttt{xtunitroot llc} ): trend nocons (unit specific) demean (within transform) lags. Under (crucial) cross-sectional independence, the test is an advancement on the generic Dickey-Fuller theory that allows the lag lengths to vary by cross-sections. The test relies on specifying a kernel (beyond our purposes) and a lag length (upper bound). The test statistic has a standard normal basis with asymptotics in \frac{\sqrt{N_{T}}}{T} ( T grows faster than N ). The test is of either all series containing unit roots ( H_{0} ) or all stationary; this is a limitation. It is recommended for moderate to large T and N.
Perform separate ADF regressions: \Delta y_{it} = \rho_{i} \Delta y_{i,t-1} + \sum_{L=1}^{p_i} \theta_{iL} \Delta y_{i,t=L} + \alpha_{mi}d_{mt} + \epsilon_{it} with d_{mt} as the vector of deterministic variables (none, drift, drift and trend). Select a max L and use t on \hat{\theta}_{iL} to attempt to simplify. Then use \Delta y_{it} = \Delta y_{i,t-L} and d_{mt} for residuals
Harris-Tzavalis ( \texttt{xtunitroot ht} ): trend nocons (unit specific) demean (within transform) altt (small sample adjust) Similar to the previous, they show that T \rightarrow \infty faster than N (rather than T fixed) leads to size distortions.
Breitung ( \texttt{xtunitroot breitung} ): trend nocons (unit specific) demean (within transform) robust (CSD) lags. Similar to LLC with a common statistic across all i.
Im, Pesaran, Shin ( \texttt{xtunitroot ips} ): trend demean (within transform) lags. They free \rho to be \rho_{i} and average individual unit root statistics. The null is that all contain unit roots while the alternative specifies at least some to be stationary. The test relies on sequential asymptotics (first T, then N). Better in small samples than LLC, but note the differences in the alternatives.
Fisher type tests ( \texttt{xtunitroot fisher} ): dfuller pperron demean lags.
Hadri (LM) ( \texttt{xtunitroot hadri} ): trend demean robust
All but the last are null hypothesis unit-root tests. Most assume balance but the fisher and IPS versions can work for unbalanced panels.
We can consider some very basic time series models.
y_{it} = X_{it}\beta + \epsilon_{it} where \epsilon_{it} = \rho \epsilon_{i,t-1} + \nu_{it} and \nu_{it} \sim N(0,\sigma^{2}_{\nu}) with stationarity forcing |\rho| < 1. We will use iterated FGLS.
In general, the transformed regression is: y_{it} - \rho y_{i,t-1} = \alpha ( 1 - \rho ) + \beta (X_{it} - \rho X_{i,t-1}) + \nu_{it} with \nu white noise.
Static model: Instantaneous impact. y_{i,t} = X_{i,t}\beta + \nu_{i,t}
Finite distributed lag: lags of x finite horizon impact (defined by lags). y_{i,t} = X_{i,t}\beta + \sum_{k=1}^{K} X_{i,t-k}\beta_{k} + \nu_{i,t}
AR(1): Errors decay geometrically, X instantaneous. (Suppose unmeasured x and think this through). y_{i,t} = X_{i,t}\beta + \nu_{i,t} + \theta\epsilon_{i,t-1}
Lagged dependent variable: lags of y [common geometric decay] y_{i,t} = X_{i,t}\beta + \phi y_{i,t-1} + \nu_{i,t}
ADL: current and lagged x and lagged y. y_{i,t} = X_{i,t}\beta + X_{i,t-1}\gamma + \phi y_{i,t-1} + \epsilon_{i,t}
Panel versions of transfer function models from Box and Jenkins time series. (each x has an impact and decay function)
y_{it} = \alpha + \gamma y_{i, t-1} + X_{it}\beta + \epsilon_{it} y_{it} = \alpha + \gamma [\alpha + \gamma y_{i, t-2} + X_{i,t-1}\beta + \epsilon_{i,t-1}] + X_{it}\beta + \epsilon_{it} y_{it} = \alpha + \gamma [\alpha + \gamma (\alpha + \gamma y_{i, t-3} + X_{i,t-2}\beta + \epsilon_{it}) + X_{i,t-1}\beta + \epsilon_{i,t-1}] + X_{it}\beta + \epsilon_{it}
We can continue substituting through to conclude that we have a geometrically decaying impact so that the long-run effect of a one-unit change in X is \frac{\beta}{1-\gamma}
But \gamma has uncertainty, it is an estimate. To show the realistic long-run impact, we need to incorporate that uncertainty.
ESSSSDA25-2W: Panel Models