Concept
Panel data is a dataset in which the behavior of each individual or entity (e.g., country, state, industry) is observed at multiple points in time.
Example:
Using panel data accounts for variables that we cannot observe or measure (e.g., individuals' innate characteristics, cultural factors, differences in business practice across companies). These variables are also called omitted variables.
Using panel data accounts for variables that change over time, but not across entities (e.g., national policies, federal regulations, international agreements).
Declaring Panel Data
- When we work with panel data in Stata, we need to declare that we have a panel dataset.
Use the following dataset:
use https://dss.princeton.edu/training/Panel101_new.dta
For declaration, type
xtset country year
The note “(strongly balanced)” refers to the fact that all countries have data for all years. If, for example, a country does not have data for any year, then the data is unbalanced. Ideally you would want to have a balanced dataset, but this is not always the case. Nevertheless, you can still run the model.
NOTE: If you get the following error after using xtset:
You need to convert ‘country’ to numeric, type:
Use ‘country1’ instead of ‘country’ in the xtset command
This guide discusses two basic techniques that we commonly use to analyze panel data: (i) fixed effects method, and (ii) random effects method.
Key Assumptions
Concept
Fixed effects method utilizes panel data to control for (omitted) variables that differ across individuals or entities (e.g., states, country), but are constant over time.
When using FE, we assume that characteristics of an individual may impact or bias the predictor or outcome variables, and we need to control for this. This is the rationale behind the assumption of the correlation between an entity’s error term and predictor variables. FE removes the effect of those time-invariant characteristics, and therefore we can assess the net effect of the predictors on the outcome variable.
In fixed effects models, the slope coefficient of the population regression line is the same for all individuals or entities, but the intercept of the population regression line varies across individuals/entities (Stokes and Watson, 2019).
Estimation
This guide discusses two different ways to estimate fixed effects models: (i) within estimator, (ii) dummy variable estimator .
(i) Within Estimator
This is the more commonly used estimator for fixed effects models. This estimator is called the "within estimator", as it uses time variation within each cross-section.
- Use the following dataset (ignore this step if you have already opened the dataset in the previous section)
use https://dss.princeton.edu/training/Panel101_new.dta
- Declare the dataset as a panel using xtset (ignore this step if you have already declared the dataset as a panel)
- Use the following command to estimate your fixed effects model
xtreg y x1 x2, fe Note: the use of fe option indicates that we are estimating a fixed effects model.
The coefficient of x1 indicates how much of Y changes over time, on average per country, when x1 increases by one unit, holding all other variables constant.
The first highlighted p-value suggests whether x1 significantly affects the dependent variable (y). As the p value is < 0.10, the coefficient for x1 is significant at 10% level.
The second highlighted p-value suggests whether the estimated model is statistically significant. As the p value is < 0.01, the model is statistically significant at 1% level.
(ii) Dummy Variable Regression
When there are a small number of fixed effects to be estimated, it is convenient to just run dummy variable regression for a FE model.
- Use the following dataset (ignore this step if you have already opened the dataset for the previous section)
use https://dss.princeton.edu/training/Panel101_new.dta
- Declare the dataset as a panel using xtset (ignore this step if you have already declared the dataset as a panel)
- Use the following command to estimate your fixed effects model
reg y x1 x2 i.country
. reg y x1 x2 i.country
Notice that the estimated coefficients for x1 and x2 are the same for both the "Within Estimator" method and the "Dummy Variable Regression" method.
Notes:
- Fixed effects do not work when lagged outcomes are included in the regression. Therefore, we do not use a lagged dependent variable as a regressor.
Key Assumption
Concept
If individual effects are strictly uncorrelated with the regressors, it may be appropriate to model the individual specific constant terms as randomly distributed across cross-sectional units. This view would be appropriate if we believe that sampled cross-sectional units were drawn from a large population.
If you have reason to believe that differences across entities have some influence on your dependent variable, then you should use random effects. In a random effects model, you need to specify those individual characteristics that may or may not influence the predictor variables. The problem with this is that data on some variables (i.e., individual characteristics such as innate ability) may not be available, hence leading to omitted variable bias in the model.
An advantage of using random effects method is that you can include time invariant variables (e.g., geographical contiguity, distance between states) in your model. In the fixed effects model, these variables are absorbed by the intercept.
Estimation
- Use the following dataset
use https://dss.princeton.edu/training/Panel101_new.dta
- Declare the dataset as a panel using xtset
- Use the following command to estimate your random effects model
xtreg y x1 x2, re Note: the use of re option indicates that we are estimating a random effects model.
The coefficient of x1 indicates how much of Y changes over time, on average per country, when x1 increases by one unit, holding all other variables constant.
The highlighted p-value suggests whether x1 significantly affects the dependent variable (y). As the p value is not < 0.10, the coefficient for x1 is not significant at 10% level.
Hausman Test
- Use the Hausman test to decide whether to use a fixed effects or random effects model.
- Procedures:
- Run a fixed effects model and save the estimates
- Run a random effects model and save the estimates
- Perform the Hausman test
- Use the following Stata commands
xtreg y x1 x2, fe
estimates store fixed
xtreg y x1 x2, re
estimates store random
hausman fixed random
...
- Decision rule: if the highlighted p value is < 0.05, use a fixed effects model. In this case, we should use a random effect model.
DSS Online Training Section https://dss.princeton.edu/training/
Princeton DSS Libguides https://libguides.princeton.edu/dss
Stata Resources https://www.stata.com/features/overview/linear-fixed-and-random-effects-models/
Angrist, J. D., & Pischke, J. S. (2009). Mostly harmless econometrics: An empiricist's companion. Princeton University Press.
Baltagi, B. (2021). Econometric analysis of panel data (6th ed). Springer.
Bartels, B. (2008). "Beyond fixed versus random effects": a framework for improving substantive and statistical analysis of panel, time-series cross-sectional, and multilevel data. The Society for Political Methodology, 9, 1-43. Available at: https://home.gwu.edu/~bartels/cluster.pdf
Baum, C. F. (2006). An introduction to modern econometrics using Stata. Stata Press.
Gelman, A., & Hill, J. (2007). Data analysis using regression and multilevel/hierarchical models. Cambridge University Press.
Greene, W. H. (2018). Econometric analysis (8th ed.). Pearson.
Hamilton, L. C. (2012). Statistics with Stata: version 12. Cengage Learning.
Hoechle, D. (2007). Robust standard errors for panel regressions with cross-sectional dependence. The stata journal, 7(3), 281-312. Available at: https://journals.sagepub.com/doi/pdf/10.1177/1536867X0700700301
Kohler, U., & Kreuter, F. (2012). Data analysis using Stata (3rd ed.). Stata Press.
Stock, J. H., & Watson, M. W. (2019). Introduction to econometrics (4th ed.). Pearson.
Wooldridge, J. M. (2010). Econometric analysis of cross section and panel data. MIT Press.
Wooldridge, J. M. (2020). Introductory econometrics: a modern approach (7th ed). Cengage Learning.
If you have questions or comments about this guide or method, please email data@Princeton.edu.