Panel data (or longitudinal data) tracks the same subjects (individuals, firms, countries) over multiple time periods
xtsum hours wage
Between: Variance between different entities (cross-sectional variation). stata panel data
* Plot a single variable over time for all units (spaghetti plot)
xtline gdp
xtreg y x1 x2, re
asdoc xtreg wage experience union i.year, fe
B. Fixed Effects (FE) Model
Allows the intercept ($\alpha_i$) to vary across entities. It "sweeps out" the time-invariant unobserved heterogeneity. Panel data (or longitudinal data) tracks the same
- Command:
xtreg y x, pa
Stata panel data — concise guide
Key commands
- xtset panelvar timevar — declare panel structure
- xtdescribe — summary of panel structure (N, T, gaps)
- xtsum varlist, by(panelvar) — panel summary stats
- xtreg depvar indepvars, fe — fixed effects (within) model
- xtreg depvar indepvars, re — random effects model
- hausman fe re — test FE vs RE
- xtivreg depvar (endog = instrument) indepvars, fe — IV with fixed effects
- xtabond depvar indepvars, lagged(depvar) — Arellano-Bond dynamic panel GMM
- xtdpdsys / xtdpdys — system/difference GMM (xtdpdsys from xtdpdsys package)
- xttest3 — test for serial correlation in panels (after xtreg, re)
- xtserial depvar indepvars — Wooldridge test for autocorrelation (user-written)
- xtunitroot llc/ips — panel unit root tests (xtunitroot llc, xtunitroot ips)
- xtwest / xtco2 — panel cointegration (user-written packages)
- xtoverid — test overidentifying restrictions for IV in panels (after xtivreg)
- xtgls depvar indepvars, corr(ar1) — GLS for panel with AR(1) errors
- xtreg, cluster(panelvar) — cluster-robust SEs (use vce(cluster panelvar))