Intro Panel Data by Kurt-Univ Basel
Intro Panel Data by Kurt-Univ Basel
Intro Panel Data by Kurt-Univ Basel
Fall 2015
Kurt Schmidheiny
Unversitat Basel
Introduction
We will assume throughout this handout that each individual i is observed in all time periods t. This is a so-called balanced panel. The
treatment of unbalanced panels is straightforward but tedious.
The T observations for individual i can be summarized as
0
0
yi1
xi1
zi
ui1
.
.
.
.
..
..
..
..
0
0
yi = yit
Xi = xit
Zi = zi
ui = uit
..
..
..
..
.
.
.
.
yiT T 1
x0iT T K
zi0 T M
uiT T 1
and N T observations for all individuals and time periods as
y=
y1
..
.
yi
..
.
yN
X=
N T 1
X1
..
.
Xi
..
.
XN
Z=
N T K
Z1
..
.
Zi
..
.
ZN
u=
N T M
u1
..
.
ui
..
.
uN
N T 1
x0it
zi0
+ ci + uit
The idiosyncratic error term uit is assumed uncorrelated with the explanatory variables of all past, current and future time periods of the
same individual. This is a strong assumption which e.g. rules out lagged
dependent variables. PL3 also assumes that the idiosyncratic error is
uncorrelated with the individual specific effect.
RE3: Identifiability
RE3 assumes that the regressors including a constant are not perfectly
collinear, that all regressors (but the constant) have non-zero variance
and not too many extreme values.
The random effects model can be written as
The remaining assumptions are divided into two sets of assumptions: the
random effects model and the fixed effects model.
where vit = ci + uit . Assuming PL2, PL4 and RE1 in the special versions
PL4a and RE2a leads to
v,1
0
0
.
..
..
..
.
.
v = V [v|X, Z] = 0
v,i
0
..
..
..
.
.
.
0
0
v,N N T N T
2.1
E[ci |Xi , zi ] = 0
c2
< (homoscedastic)
2
b) V [ci |Xi , zi ] = c,i
(Xi , zi ) < (heteroscedastic)
v2
c2
..
.
c2
c2
v2
..
.
c2
..
.
c2
c2
..
.
v2
T T
In the fixed effects model, the individual-specific effect is a random variable that is allowed to be correlated with the explanatory variables.
The pooled OLS estimator ignores the panel structure of the data and
simply estimates , and as
bP OLS
1
b
0
0
P OLS = (W W ) W y
bP OLS
where W = [N T X Z] and N T is a N T 1 vector of ones.
Random effects model : The pooled OLS estimator of , and is unbiased under PL1, PL2, PL3, RE1, and RE3 in small samples. Additionally assuming PL4 and normally distributed idiosyncratic and individualspecific errors, it is normally distributed in small samples. It is consistent
and approximately normally distributed under PL1, PL2, PL3, PL4, RE1,
and RE3a in samples with a large number of individuals (N ). However, the pooled OLS estimator is not efficient. More importantly, the
usual standard errors of the pooled OLS estimator are incorrect and tests
(t-, F -, z-, Wald-) based on them are not valid. Correct standard errors
can be estimated with the so-called cluster-robust covariance estimator
treating each individual as a cluster (see the handout on Clustering in
the Linear Model).
Fixed effects model : The pooled OLS estimators of , and are
biased and inconsistent, because the variable ci is omitted and potentially
correlated with the other regressors.
bRE
1
b
0 b 1
b v 1 y.
W 0
W
RE = W
v
bRE
where W = [N T X Z] and N T is a N T 1 vector of ones.
The error covariance matrix v is assumed block-diagonal with equicorrelated diagonal elements v,i as in section 2.1 which depend on the two
unknown parameters v2 and c2 only. There are many different ways to
estimate these two parameters. For example,
bv2 =
where
bu2
T
N
1 XX 2
vb
N T t=1 i=1 it
bc2 =
bv2
bu2
T X
N
X
1
(b
vit vbi )2
=
N T N t=1 i=1
PT
and vbit = yit P OLS x0it bP OLS zi0
bP OLS and vbi = 1/T t=1 vbit . The
degree of freedom correction in
bu2 is also asymptotically important when
N .
bRE
bRE
b
A
RE N , Avar bRE
bRE
bRE
bc2 are conAssuming the equicorrelated model (PL4a and RE2a),
bv2 and
2
2
b
bRE , RE and
bRE are
sistent estimators of v and c , respectively. Then
asymptotically efficient and the asymptotic variance can be consistently
estimated as
bRE
1
0 b 1
[
Avar
bRE = W
v W
bRE
Allowing for arbitrary conditional variances and for serial correlation in
v,i (PL4c and RE2b), the asymptotic variance can be consistently estimated with the so-called cluster-robust covariance estimator treating
each individual as a cluster (see the handout on Clustering in the Linear
Model). In both cases, the usual tests (z-, Wald-) for large samples can
be performed.
In practice, we can rarely be sure about equicorrelated errors and
better always use cluster-robust standard errors for the RE estimator.
Fixed effects model : Under the assumptions of the fixed effects model
(FE1, i.e. RE1 violated), the random effects estimators of , and are
biased and inconsistent, because the variable ci is omitted and potentially
correlated with the other regressors.
0 y
bF E = X
X
Note that the parameters and are not estimated by the within estimator.
Random effects model and fixed effects model : The fixed effects estimator of is unbiased under PL1, PL2, PL3, and FE3 in small samples.
Additionally assuming PL4 and normally distributed idiosyncratic errors,
it is normally distributed in small samples. Assuming homoscedastic
erh
i
rors with no serial correlation (PL4a), the variance V bF E |X can be
unbiasedly estimated as
h
i
1
0X
Vb bF E |X =
bu2 X
b0 u
b
bit = yit x
where
bu2 = u
/(N T N K) and u
0it bF E . Note the non-usual
degrees of freedom correction. The usual z- and F -tests can be performed.
The FE estimator is consistent and asymptotically normally distributed
under PL1 - PL4 and FE3 when the number of individuals N even
if T is fixed. It can therefore be approximated in samples with many
individual observations N as
h
i
A
bF E N , Avar bF E
Assuming homoscedastic errors with no serial correlation (PL4a), the
asymptotic variance can be consistently estimated as
h
i
1
0X
[ bF E =
Avar
bu2 X
b u
b/(N T N ).
where
bu2 = u
Allowing for heteroscedasticity and serial correlation of unknown form
(PL4c), the asymptotic variance Avar[bk ] can be consistently estimated
with the so-called cluster-robust covariance estimator treating each individual as a cluster (see the handout on Clustering in the Linear Model).
In both cases, the usual tests (z-, Wald-) for large samples can be performed.
In practice, the idiosyncratic errors are often serially correlated (violating PL4a) when T > 2. Bertrand, Duflo and Mullainathan (2004) show
that the usual standard errors of the fixed effects estimator are drastically
understated in the presence of serial correlation. It is therefore advisable
to always use cluster-robust standard errors for the fixed effects estimator.
The least squares dummy variables (LSDV) estimator is pooled OLS including a set of N 1 dummy variables which identify the individuals and
hence an additional N 1 parameters. Note that one of the individual
dummies is dropped because we include a constant. Time-invariant explanatory variables, zi , are dropped because they are perfectly collinear
with the individual dummy variables.
The LSDV estimator of is numerically identical with the FE estimator and therefore consistent under the same assumptions. The LSDV
estimators of the additional parameters for the individual-specific dummy
variables, however, are inconsistent as the number of parameters goes to
infinity as N . This so-called incidental parameters problem generally biases all parameters in non-linear fixed effects models like the probit
model.
10
We often also suspect that there are time-specific effects t which affect
all individuals in the same way
yit = + x0it + zi0 + t + ci + uit .
We can estimate this extended model by including a dummy variable for
each time period. Assuming a fixed number of time periods T and the
number of individuals N , both the RE estimator and the FE estimator are consistent using time dummy variables under above conditions.
11
10
12
Stata provides a series of commands that are especially designed for panel
data. See help xt for an overview.
Stata requires panel data in the so-called long form: there is one
line for every individual and every time observation. The very powerful
Stata command reshape helps transforming data into this format. Before
working with panel data commands, we have to tell Stata the variables
that identify the individual and the time period. For example, load data
and define individuals (variable idcode) and time periods (variable year )
P
where xi = 1/T t xit are the time averages of all time-varying regressors.
Include time fixed t if they are included in the RE and FE estimation.
A joint Wald-test on H0 : = 0 tests RE1. Use cluster-robust standard
errors to allow for heteroscedasticity and serial correlation.
Note: Assumption RE1 is an extremely strong assumption and the FE
estimator is almost always much more convincing than the RE estimator.
Not rejecting RE1 does not mean accepting it. Interest in the effect of a
time-invariant variable is no sufficient reason to use the RE estimator.
webuse nlswork.dta
Note that the effect of time-constant variables like grade is not identified
by the fixed effects estimator. The parameter reported as cons in the
P
Stata output is the average fixed effect 1/N i ci . Stata uses N T
N K M degrees of freedom for small sample tests. Cluster-robust
Huber/White standard errors are reported with the vce option:
xtreg ln_wage ttl_exp ttl_exp2, fe vce(cluster idcode)
Since version 10, Stata automatically assumes clustering with robust standard errors in fixed effects estimations. So we could also just use
xtreg ln_wage ttl_exp ttl_exp2, fe vce(robust)
13
Stata reports asymptotic z- and Wald-tests with random effects estimation. Cluster-robust Huber/White standard errors are reported with:
xtreg ln_wage grade ttl_exp ttl_exp2, re vce(cluster idcode)
11
14
Implementation in R 2.13
The R package plm provides a series of functions and data structures that
are especially designed for panel data.
The plm package works with data stored in a structured dataframe
format. The function plm.data transforms data from the so-called long
form into the plm structure. Long form data means that there is one line
for every individual and every time observation. For example, load data
> library(foreign)
> nlswork <- read.dta("http://www.stata-press.com/data/r11/nlswork.dta")
and define individuals (variable idcode) and time periods (variable year )
> library(plm)
> pnlswork <- plm.data(nlswork, c("idcode","year"))
The fixed effects estimator is calculated by the R function plm and its
model option within:
> ffe<-plm(ln_wage~ttl_exp+I(ttl_exp^2), model="within", data = pnlswork)
> summary(ffe)
Note that the effect of time-constant variables like grade is not identified by the fixed effects estimator. Cluster-robust Huber/White standard
errors are reported with the lmtest package:
where the vce option was used to report correct cluster-robust Huber/White
standard errors.
The least squares dummy variables estimator is calculated by including
dummy variables for individuals in pooled OLS. It is numerically only
feasibly with relatively few individuals:
drop if idcode > 50
xi: regress ln_wage ttl_exp ttl_exp2 i.idcode
where only the first 43 individuals are used in the estimation. The long
list of estimated fixed effects can suppressed by using the areg command:
areg ln_wage ttl_exp ttl_exp2, absorb(idcode)
> library(lmtest)
> coeftest(ffe, vcov=vcovHC(ffe, cluster="group"))
15
> library(lmtest)
> coeftest(fre, vcov=vcovHC(fre, cluster="group"))
The Hausman test is calculated by estimating RE and FE and then comparing the estimates:
> phtest(ffe, fre)
where the lmtest package was used to report correct cluster-robust Huber/White standard errors.
The least squares dummy variables estimator is calculated by including
dummy variables for individuals in pooled OLS. It is numerically only
feasibly with relatively few individuals:
> lsdv <- lm(ln_wage~ttl_exp+I(ttl_exp^2)+factor(idcode),
data = nlswork, subset=(idcode<=50))
> summary(lsdv)
16
References
Introductory textbooks
Stock, James H. and Mark W. Watson (2012), Introduction to Econometrics, 3rd ed., Pearson Addison-Wesley. Chapter 10.
Wooldridge, Jeffrey M. (2009), Introductory Econometrics: A Modern
Approach, 4th ed., South-Western Cengage Learning. Ch. 13 and 14.
Advanced textbooks
Cameron, A. Colin and Pravin K. Trivedi (2005), Microeconometrics:
Methods and Applications, Cambridge University Press. Chapter 21.
Wooldridge, Jeffrey M. (2010), Econometric Analysis of Cross Section and
Panel Data, MIT Press. Chapter 10.
Companion textbooks
Angrist, Joshua D. and Jorn-Steffen Pischke (2009), Mostly Harmless
Econometrics: An Empiricists Companion, Princeton University Press.
Chapter 5.