Panel Data Methods For Microeconomics Using Stata
Panel Data Methods For Microeconomics Using Stata
Panel Data Methods For Microeconomics Using Stata
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 1 / 39 and
1. Introduction
Panel data are repeated measures on individuals (i ) over time (t ). Regress yit on xit for i = 1, ..., N and t = 1, ..., T . Complications compared to cross-section data:
1
Inference: correct (inate) standard errors. This is because each additional year of data is not independent of previous years. Modelling: richer models and estimation methods are possible with repeated measures. Fixed eects and dynamic models are examples. Methodology: dierent areas of applied statistics may apply dierent methods to the same panel data set.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 2 / 39 and
This talk: overview of panel data methods and xt commands for Stata 10 most commonly used by microeconometricians. Three specializations to general panel methods:
1
Short panel: data on many individual units and few time periods. Then data viewed as clustered on the individual unit. Many panel methods also apply to clustered data such as cross-section individual-level surveys clustered at the village level. Causation from observational data: use repeated measures to estimate key marginal eects that are causative rather than mere correlation. Fixed eects: assume time-invariant individual-specic eects. IV: use data from other periods as instruments. Dynamic models: regressors include lagged dependent variables.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 3 / 39 and
Outline
1 2 3 4 5 6 7 8 9 10 11 12
Introduction Linear models overview Example: wages Standard linear panel estimators Linear panel IV estimators Linear dynamic models Long panels Random coe cient models Clustered data Nonlinear panel models overview Nonlinear panel models estimators Conclusions
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 4 / 39 and
A. Colin Cameron
6 7
Regular time intervals assumed. Unbalanced panel okay (xt commands handle unbalanced data). [Should then rule out selection/attrition bias]. Short panel assumed, with T small and N ! . [Versus long panels, with T ! and N small or N ! .] Errors are correlated. [For short panel: panel over t for given i , but not over i .] Parameters may vary over individuals or time. Intercept: Individual-specic eects model (xed or random eects). Slopes: Pooling and random coe cients models. Regressors: time-invariant, individual-invariant, or vary over both. Prediction: ignored. [Not always possible even if marginal eects computed.] Dynamic models: possible. [Usually static models are estimated.]
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 5 / 39 and
A. Colin Cameron
(1)
(2)
(3)
for short panels where time-eects are included as dummies in xit . Random coe cients model allows slopes to vary over i
0 yit = i + xit i + it .
A. Colin Cameron
(4)
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 6 / 39 and
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 7 / 39 and
Fundamental divide
Microeconometricians: xed eects Many others: random eects.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 8 / 39 and
Many methods assume it and i (if present) are iid. Yields wrong standard errors if heteroskedasticity or if errors not equicorrelated over time for a given individual. For short panel can relax and use cluster-robust inference.
Allows heteroskedasticity and general correlation over time for given i . Independence over i is still assumed.
Use option vce(cluster) if available (xtreg, xtgee). This is not available for many xt commands.
then use option vce(boot) or vce(cluster) but only if the estimator being used is still consistent.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting Based October on 25, A. Colin 2007 Cameron 9 / 39 and
Panel summary
xtset; xtdescribe; xtsum; xtdata; xtline; xttab; xttran Pooled OLS regress Feasible GLS xtgee, family(gaussian) xtgls; xtpcse Random eects xtreg, re; xtregar, re Fixed eects xtreg, fe; xtregar, fe Random slopes xtmixed; quadchk; xtrc First dierences regress (with dierenced data) Static IV xtivreg; xthtaylor Dynamic IV xtabond; xtdpdsys; xtdpd
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 10 / 39 and
PSID wage data 1976-82 on 595 individuals. Balanced. Source: Baltagi and Khanti-Akom (1990). [Corrected version of Cornwell and Rupert (1998).] Goal: estimate causative eect of education on wages. Complication: education is time-invariant in these data. Rules out xed eects. Need to use IV methods (Hausman-Taylor).
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 11 / 39 and
xt commands require data to be in long form. Then each observation is an individual-time pair. Original data are often in wide form. Then an observation combines all time periods for an individual, or all individuals for a time period. Use reshape long to convert from wide to long. xtset is used to dene i and t .
xtset id t is an example allows use of panel commands and some time series operators.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 12 / 39 and
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 13 / 39 and
describe, summarize and tabulate confound cross-section and time series variation. Instead use specialized panel commands:
xtdescribe: extent to which panel is unbalanced xtsum: separate within (over time) and between (over individuals) variation xttab: tabulations within and between for discrete data e.g. binary xttrans: transition frequencies for discrete data xtline: time series plot for each individual on one chart xtdata: scatterplots for within and between variation.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 14 / 39 and
Pooled OLS: OLS of yit on xit . Between estimator: OLS of y i on xi . Random eects estimator: FGLS in RE model. b i ) on (xit b Equals OLS i xi ); p of (yit i y 2 2 i = 1 / ( Ti + 2 ) . Within estimator or FE estimator: OLS of (yit First dierence estimator: OLS of (yit Implementation:
xtreg does 2-4 with options be, fe, re xtgee does 3 (with option exchangeable) regress does 1 and 5.
4 5
y i ) on (xit on (xit xi ,t
xi ).
1 ).
yi ,t
1)
4.2 Example
Coe cients vary considerably across OLS, FE and RE estimators. Cluster-robust standard errors (su x rob) larger even for FE and RE. Coe cient of ed not identied for FE as time-invariant regressor.
A. Colin Cameron Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 16 / 39 and
b 1 ,W ,
Problem: hausman command assumes RE is fully e cient. But not the case here as robust se s for RE dier from default se s. So hausman is incorrect. Instead implement Hausman test using suest or panel bootstrap or Wooldridge (2002) robust version of Hausman test.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 17 / 39 and
5.1 Panel IV
Consider model with possibly transformed variables: yit = + xit0 + uit , where yit = yit or yit = y i for BE or yit = (yit yit = (yit i y i ) for RE. OLS is inconsistent if E[uit jxit ] = 0. y i ) for FE or
So do IV estimation with instruments zit satisfy E[uit jzit ] = 0. Command xtivreg is used, with options be, re or fe. This command does not have option for robust standard errors.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 18 / 39 and
Solution:
Assume the endogenous regressor is correlated only with i (and not with it ) Use exogenous time-varying regressors xit from other periods as instruments
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 19 / 39 and
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 20 / 39 and
0 + xit + i + it .
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 21 / 39 and
(yit
yi ,t
1)
= (yi ,t
yi ,t
2 ) + (xit
xi0 ,t
1 )
+ (it
i ,t i ,t
1 ). 1)
OLS inconsistent as (yi ,t 1 yi ,t 2 ) correlated with (it (even under assumption it is serially uncorrelated). But yi ,t 2 is not correlated with (it i ,t 1 ), so can use yi ,t 2 as an instrument for (yi ,t 1 yi ,t
2 ).
Arellano-Bond is a variation that uses unbalanced set of instruments with further lags as instruments. For t = 3 can use yi 1 , for t = 4 can use yi 1 and yi 2 , and so on. Stata commands
xtabond for Arellano-Bond xtdpdsys for Blundell-Bond (more e cient than xtabond) xtdpd for more complicated models than xtabond and xtdpdsys.
A. Colin Cameron Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 22 / 39 and
For short panels asymptotics are T xed and N ! . For long panels asymptotics are for T !
A dynamic model for the errors is specied, such as AR(1) error Errors may be correlated over individuals Individual-specic eects can be just individual dummies Furthermore if N is small and T large can allow slopes to dier across individuals and test for poolability.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 23 / 39 and
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 24 / 39 and
Generalize random eects model to random slopes. Command xtrc estimates the random coe cients model
0 yit = i + xit i + it ,
where (i , i ) are iid with mean (, ) and variance matrix and it is iid. No vce(robust) option but can use vce(boot) if short panel.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 25 / 39 and
Not used in microeconometrics but used in many other disciplines. Stack all observations for individual i and specify yi = Xi + Zi ui + i where ui is iid (0, G) and Zi is called a design matrix. Random eects: Zi = e (a vector of ones) and ui = i Random coe cients: Zi = Xi . Other models including multi-level models are possible. Command xtmixed estimates this model.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 26 / 39 and
Consider data on individual i in village j with clustering on village. A cluster-specic model (here village-specic) species
0 yji = i + xji + ji .
Here clustering is on village (not individual) and the repeated measures are over individuals (not time). Use xtset village id Assuming equicorrelated errors can be more reasonable here than with panel data (where correlation dampens over time). So perhaps less need for vce(cluster) after xtreg
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 27 / 39 and
If i is random use:
regress with option vce(cluster village) xtreg,re xtgee with option exchangeable xtmixed for richer models of error structure
If i is xed use:
xtreg,fe
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 28 / 39 and
Complications
Random eects often not tractable so need numerical integration Fixed eects models in short panels are generally not estimable due to the incidental parameters problem.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 29 / 39 and
where denotes additional model parameters such as variance parameters and i is an individual eect. A conditional mean model may be specied, with additive eects
0 E[yit ji , xit ] = i + g (xit )
(6)
0 g (xit ).
(7)
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 30 / 39 and
Counts Pooled poisson negbin GEE (PA) xtgee,family(poisson) xtgee,family(nbinomial) RE xtpoisson, re xtnegbin, fe Random slopes xtmepoisson FE xtpoisson, fe xtnegbin, fe plus tobit and xttobit.
Binary logit probit xtgee,family(binomial) link(logit xtgee,family(poisson) link(probit xtlogit, re xtprobit, re xtmelogit xtlogit, fe
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 31 / 39 and
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 32 / 39 and
(8)
Analytical solution:
For Poisson with gamma random eect For negative binomial with gamma eect Use xtpoisson, re and xtnbreg, re
No analytical solution:
For other models. Instead use numerical integration (only univariate integration is required). Assume normally distributed random eects. Use re option for xtlogit, xtprobit Use normal option for xtpoisson and xtnegbin
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 33 / 39 and
A. Colin Cameron
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 34 / 39 and
Stata commands
xtlogit, fe xtpoisson, fe (better to use xtpqml as robust se s) xtnegbin, fe
Fixed eects extended to dynamic models for logit and probit. No Stata command.
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 35 / 39 and
12. Conclusion
Stata provides commands for panel models and estimators commonly used in microeconometrics and biostatistics. Stata also provides diagnostics and postestimation commands, not presented here. The emphasis is on short panels. Some commands provide cluster-robust standard errors, some do not. A big distinction is between xed eects models, emphasized by microeconometricians, and random eects and mixed models favored by many others. Extensions to nonlinear panel models exist, though FE models may not be estimable with short panels. This presentation draws on two chapters in Cameron and Trivedi, Microeconometrics using Stata, forthcoming.
A. Colin Cameron Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 36 / 39 and
Book Outline
For Cameron and Trivedi, Microeconometrics using Stata, forthcoming. 1. Stata basics 2. Data management and graphics 3. Linear regression basics 4. Simulation 5. GLS regression 6. Linear instrumental variable regression 7. Quantile regression 8. Linear panel models 9. Nonlinear regression methods 10. Nonlinear optimization methods 11. Testing methods 12. Bootstrap methods
A. Colin Cameron Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 37 / 39 and
13. Binary outcome models 14. Multinomial models 15. Tobit and selection models 16. Count models 17. Nonlinear panel models 18. Topics A. Programming in Stata B. Mata
A. Colin Cameron
Univ. of California - Davis (Prepared Panel formethods West Coast for Stata Stata UsersGroup Meeting October Based on 25, A. 2007 Colin Cameron 38 / 39 and