The same units over time? (Panel data, fixed and random effects)
In brief
With panel data the same unit is measured several times: a firm every year, a person in several surveys, a country over decades. That has an advantage and a problem. The advantage: you can compare each unit with itself and so take out everything that stays the same for it and was never measured (company culture, location). The problem: measurements of the same unit are not independent, ordinary standard errors are then too small.
The models at a glance
- Fixed effects (within): every unit gets its own starting level; the estimate comes only from changes within the units. Features that never change within a unit drop out.
- Random effects: the differences between the units are treated as chance, unrelated to the features. The comparison between units is then used as well, so the estimate is more precise. If the assumption does not hold, it is biased.
- Pooled: all rows in one pot, as if they were all different units. Between: only the means per unit. Both mainly show how far apart the comparison between and within units is.
An example with real data
Grunfeld data: ten large US firms, 1935 to 1954 (200 observations). The investment (inv) is explained by the market value of the firm (value) and its capital stock (capital).
| Model | b for value | b for capital | Standard error value (classical / cluster-robust) |
|---|---|---|---|
| Fixed effects | 0.1101 | 0.3101 | 0.0119 / 0.0152 |
| Random effects | 0.1098 | 0.3081 | - |
| Pooled | 0.1156 | 0.2307 | 0.0058 / 0.0159 |
| Between | 0.1346 | 0.0320 | - |
- The firms differ clearly: F test for group effects F(9, 188) = 49.18, p < .001. A model that treats all firms the same (pooled) is therefore not appropriate.
- The Hausman test (fixed against random effects) gives χ²(2) = 2.33, p = .312: no clear difference between the two estimates. That does not prove that random effects hold; with ten firms the test has little power.
- For pooled the cluster-robust standard error of value is almost three times the classical one (0.0159 against 0.0058): ordinary standard errors would have overstated the precision considerably.
- The capital stock hardly acts between firms (between: 0.032) but clearly within firms (0.310): firms with a lot of capital do not invest more, but the same firm invests more when its capital grows.
When do I use it?
When the same units were measured several times and you want to know how changes in a feature go with changes in the outcome without unchanging differences between units getting in the way. Whoever only wants to describe the change of one unit over time uses repeated measures or the growth curve model; whoever compares people in groups (classes, schools) at one time point uses the multilevel model.
Requirements
- A column that identifies each unit (firm number, person identifier). Every unit should appear several times; at least two units, preferably many more.
- Features that change within the units. What always stays the same for each unit (sex, year of founding) cannot be estimated with fixed effects; Statable names such columns.
- Random effects and the Hausman test only for a balanced panel, that is the same number of time points for every unit; with unequal numbers there are several common ways of calculating and Statable does not pick one secretly.
- With fewer than about 30 units cluster-robust standard errors are unreliable (too small); Statable points this out.
How it works in Statable
- Open a file in which every row is one unit at one time point (for example firm and year in one column each) and run a question "Can something be predicted? (regression)".
- Under the result, at "Calculate differently", open "The same units over time? (panel data, fixed and random effects)". Ctrl+K: "panel data".
- Choose the column that identifies the unit (group identifier), the number to be explained and the features that change within a unit; then "Calculate panel".
- With "As R script with data (.zip)" you take the calculation with you; it needs only base R, no package.
For each feature the table shows all models one below the other, with classical and cluster-robust standard errors. The cluster-robust variance follows the formula of Stata and the R package sandwich (CR1: G/(G−1) · (N−1)/(N−k)); the R package plm uses only N/(N−k) for fixed effects and gets somewhat smaller standard errors. The p values of the cluster-robust errors use the t distribution with G − 1 degrees of freedom (G = number of units).
Reading and reporting the result
A panel regression of the investment of ten firms over 20 years (N = 200) with fixed effects gave b = 0.110 (cluster-robust SE = 0.015) for market value and b = 0.310 (cluster-robust SE = 0.053) for capital stock. The F test for firm effects was clear, F(9, 188) = 49.18, p < .001; the Hausman test showed no clear difference from random effects, χ²(2) = 2.33, p = .312.
Limits
- Fixed effects rule out everything that stays the same for a unit, but not what changes for it together with the feature and was not measured (for example an economic shock). The model therefore does not prove causes.
- The classical Hausman test assumes ordinary standard errors and does not hold when you calculate cluster-robust; a test that takes this into account (Mundlak regression, robust version) belongs in R. It also says little about bias when there are only a few units.
- Statable does not calculate time effects (year effects) or two-way clustering; whoever needs them uses the R package plm or fixest.
What is often misunderstood
Sources
Croissant, Y. & Millo, G. (2008). Panel Data Econometrics in R: the plm Package. Journal of Statistical Software, 27(2) (open access). Cameron, A. C. & Miller, D. L. (2015). A Practitioner's Guide to Cluster-Robust Inference. Journal of Human Resources, 50(2), 317-372. Cunningham, S. Causal Inference: The Mixtape (mixtape.scunning.com, open access). Data: Grunfeld, Y. (1958), prepared in the R packages plm and AER (GPL).
Take away
- Fixed effects compare each unit with itself; random effects also use the comparison between units but need an assumption that the Hausman test checks only roughly.
- Measurements of the same unit are not independent: cluster-robust standard errors are part of it, and fewer than about 30 units make even them unreliable.
- A feature that never changes within a unit cannot be estimated with fixed effects.
- The panel also describes relationships; causes need a design (experiment, instrument, difference-in-differences) and good reasons.