Chapter 35 of 57
Panel Data and Fixed Effects, on One Page
Created Jul 5, 2026 Updated Oct 25, 2026
Panel data (a.k.a. longitudinal data) is what you have when you follow the same units — people, firms, countries — across several time periods, instead of a single snapshot of many different units. That repetition buys you something a plain cross-section can't: a way to erase every stable trait of a unit, whether you measured it or not.
Here's the problem it solves. Suppose each unit i has some fixed, unobserved characteristic α_i — a firm's management culture, a person's baseline ability — that shapes y and correlates with your regressor X. That's textbook endogeneity: α_i sits in the error term, and pooled OLS across all units confuses "units with high X" for "units that were going to have high y anyway." The estimate can be badly off — even point the wrong way (a Simpson's paradox).
The within-transformation is the trick. Write the model with that nuisance in it, one intercept per unit:
Then, for each unit, subtract that unit's own average over time from every variable:
Anything constant within a unit — including the whole nuisance — equals its own mean, so it cancels. What's left is pure within-unit variation: how y moves when X moves for the same unit. The slope of that is the fixed-effects estimate of β. You've controlled for every time-invariant confounder without ever naming one.
That is a statement about the stable confounder only. For the slope to be causal, the changes in X within a unit still have to be exogenous — formally , the strict exogeneity the estimator leans on.
Each colour is one unit watched over time. Inside every cluster the slope is the true β, but the clusters are stacked along a different line because each unit's hidden intercept α tracks its X-level. The dashed pooled OLS line chases that between-unit arrangement and gets β wrong — turn confounding φ negative enough and it points the opposite way (Simpson's paradox). Tick demean to apply the within-transformation: subtracting each unit's own mean cancels α, every cluster slides onto the origin, and the slope of the pooled-within cloud is the fixed-effects estimate — back on β.
Three things to carry away:
- The cost: fixed effects burn all between-unit variation, so anything that never changes for a unit (someone's sex, a country's coastline) drops out — you simply can't estimate its effect this way.
- Standard errors need care. Observations from the same unit are usually correlated across time, and conventional standard errors can understate uncertainty badly when they are. Cluster-robust standard errors, clustered by unit, account for that dependence — with their own caveat that they need a decent number of clusters to behave.
- Two-way and beyond. Add time fixed effects to absorb shocks common to all units in a period. That machinery leads into difference-in-differences, though it does not by itself make a DiD: that design needs parallel trends for the untreated outcome. And when treatment arrives at different times for different units, the standard two-way estimate can mislead — with heterogeneous effects it quietly uses already-treated units as controls and weights the comparisons badly.
Fixed effects defeat time-invariant confounding, not endogeneity in general. A confounder that moves within a unit and tracks X, reverse causality, feedback from past outcomes — each still biases the estimate, and each needs something more: the confounder measured and controlled for, time effects for common shocks, a design built around the timing, or an instrument. The full treatment — within vs first-differences, random effects, clustered SEs, staggered DiD — is in the Panel Data (Fixed Effects) note.