Panel Data: Fixed Effects, Random Effects, and the Hausman Test

Lectures 13–15

Henrique Veras

PIMES/UFPE

Where this lecture sits

DGPIdentificationEstimationAsymptoticsInference
Computation

  • The panel DGP: \(y_{it}=\mathbf x_{it}'\bbeta+\alpha_i+\varepsilon_{it}\) — an unobserved, unit-specific effect \(\alpha_i\) on top of the usual error.
  • The one question: is \(\alpha_i\) correlated with \(\mathbf x_{it}\)? If yes, ignoring it is omitted-variable bias (Lecture 9) → pooled OLS inconsistent.
  • Two answers. Fixed effects: sweep \(\alpha_i\) out (within) — robust, assumption-free about \(\alpha_i\). Random effects: model it as noise — GLS, efficient, keeps time-invariant regressors.
  • The arc: three sources of variation → FE → RE → Hausman chooses → FE in practice → DiD.
What is the DGP?—What is the DGP, here?

\(y_{it}=\mathbf x_{it}'\bbeta+\alpha_i+\varepsilon_{it}\), with \(\varepsilon_{it}\) the usual idiosyncratic shock and \(\alpha_i\) a time-invariant unit effect. Everything hinges on \(\Cov(\alpha_i,\mathbf x_{it})\): zero → random effects; nonzero → fixed effects.

Part I · The panel model

Units observed over time

A panel follows \(n\) units across \(T\) periods. The payoff is a term for everything about a unit that does not change over time — \(\alpha_i\) — that a single cross-section could never separate from the error.

  • Balanced vs. unbalanced. \(T_i=T\) for all \(i\) (balanced) or \(T_i\) varying (unbalanced, the common case — attrition, entry/exit). The algebra is the same; keep track of \(\sum_i T_i\).
  • What is \(\alpha_i\)? The unit’s fixed, unobserved traits — a firm’s management, a worker’s ability, a country’s institutions. It loads identically on every period of unit \(i\).
  • Two regimes, one question. Treating \(\alpha_i\) as a parameter (correlated with \(\mathbf x\), arbitrary) → fixed effects. Treating it as a random draw (uncorrelated with \(\mathbf x\)) → random effects. The names mislead; the content is \(\Cov(\alpha_i,\mathbf x_{it})\).
  • Two kinds of variation the data now contain: between units (how units differ on average) and within a unit (how it moves over time). Which one we use is the whole story.

Pooled OLS: the benchmark and its two failures

Stack all \(\sum_i T_i\) observations and run OLS, ignoring the panel structure. Fold \(\alpha_i\) into a composite error \(w_{it}=\alpha_i+\varepsilon_{it}\): \[y_{it}=\mathbf x_{it}'\bbeta+\underbrace{\alpha_i+\varepsilon_{it}}_{w_{it}}.\] If the classical assumptions held for \(w_{it}\), pooled OLS would be efficient and we would be done. They usually do not — in two distinct ways.

  • Failure 1 — inconsistency. If \(\Cov(\alpha_i,\mathbf x_{it})\neq0\), the regressor is correlated with the error → pooled OLS is biased and inconsistent. This is textbook omitted-variable bias (Lecture 9); no standard error repairs a biased point estimate.
  • Failure 2 — wrong standard errors. Even if \(\Cov=0\), \(w_{it}\) is correlated within a unit across time (the shared \(\alpha_i\)), so default SEs are far too small and \(t\)-stats too big.
  • Two problems, two tools. Inconsistency needs a new estimator (fixed effects). Wrong SEs need cluster-robust inference or GLS (random effects). Keep them separate.

Cluster-robust inference for the pooled model

Take Failure 2 first. Stack unit \(i\)’s \(T_i\) rows as \(\mathbf y_i=\mathbf X_i\bbeta+\mathbf w_i\), with \(\Var[\mathbf w_i\mid\mathbf X_i]=\boldsymbol\Omega_i\) — unknown, but block-diagonal across units (independence across \(i\), arbitrary correlation within). The sandwich then sums over units: \[\widehat{\Var}(\mathbf b)=\Big(\textstyle\sum_i\mathbf X_i'\mathbf X_i\Big)^{-1}\Big(\sum_i\mathbf X_i'\hat{\mathbf w}_i\hat{\mathbf w}_i'\mathbf X_i\Big)\Big(\sum_i\mathbf X_i'\mathbf X_i\Big)^{-1}.\]

  • This is the cluster-robust estimator of Lecture 7, one block per unit: the latent \(\alpha_i\) left in the error carries across all of a unit’s periods, so observations within a unit are dependent.
  • What must be large is the number of clusters (here, units \(n\)), not \(T\) — consistency is in \(n\to\infty\).
  • The bread \((\sum\mathbf X_i'\mathbf X_i)^{-1}\) and meat \(\sum\mathbf X_i'\hat{\mathbf w}_i\hat{\mathbf w}_i'\mathbf X_i\) are the familiar pieces; only the middle is estimated. Ignoring the within-unit correlation can shrink the SE several-fold.
Researcher's Toolbox—Which level do you cluster on?

Cluster at the coarsest grouping where errors may correlate: a genuine hierarchy (students in schools over time) moves the cluster up to the school, whose block absorbs both over-time and across-student dependence. Clustering too fine understates the SE; with few clusters, use the wild cluster bootstrap.

Part II · Three ways to use the variation

The between (group-means) estimator

Collapse each unit to its time-average and regress the means on the means: \[\bar y_i=\bar{\mathbf x}_i'\bbeta+\bar w_i,\qquad \bar w_i=\alpha_i+\bar\varepsilon_i.\] This uses only the between-unit (cross-sectional) variation.

  • It throws away all within variation — one observation per unit — and estimates \(\bbeta\) from how units differ on average.
  • It inherits pooled OLS’s consistency problem. Averaging keeps \(\alpha_i\) in \(\bar w_i\); if \(\Cov(\alpha_i,\bar{\mathbf x}_i)\neq0\), the between estimator is biased and inconsistent — the latent effect is baked into the group means.
  • Why we still care: it is one of three estimators (pooled, within, between) whose relationship organises the whole subject (next slide), and it reappears inside the random-effects variance components.

First differences

A second way to kill \(\alpha_i\): difference adjacent periods. Since \(\alpha_i\) is constant, it drops: \[y_{it}-y_{i,t-1}=(\mathbf x_{it}-\mathbf x_{i,t-1})'\bbeta+(\varepsilon_{it}-\varepsilon_{i,t-1}) \quad\Longrightarrow\quad \Delta y_{it}=\Delta\mathbf x_{it}'\bbeta+\Delta\varepsilon_{it}.\]

  • FD removes the heterogeneity \(\alpha_i\) with no assumption about it — using only within-unit (over-time) variation.
  • The cost: it also removes every time-invariant regressor (\(\Delta x=0\) for them) — you cannot estimate the return to a fixed trait (sex, a permanent policy). (This is the price of using only over-time variation — the next estimator pays it too.)
  • The error is now an MA(1). \(u_{it}=\varepsilon_{it}-\varepsilon_{i,t-1}\) is autocorrelated by construction.

The within estimator

The third option — and the one that makes panels powerful. Subtract each unit’s time-average (the within, or demeaning, transformation). Since \(\alpha_i\) is constant over \(t\), it cancels — with no assumption about it: \[\underbrace{y_{it}-\bar y_i}_{\ddot y_{it}}=(\mathbf x_{it}-\bar{\mathbf x}_i)'\bbeta+(\varepsilon_{it}-\bar\varepsilon_i) \quad\Longrightarrow\quad \hat\bbeta_{\text{within}}=(\ddot{\mathbf X}'\ddot{\mathbf X})^{-1}\ddot{\mathbf X}'\ddot{\mathbf y}.\]

  • It uses only within-unit variation — how \(\mathbf x_{it}\) moves for a given unit over time. Unlike pooled and between, it does not need \(\Cov(\alpha_i,\mathbf x_{it})=0\): demeaning removes \(\alpha_i\) outright, whatever its correlation with \(\mathbf x\).
  • Same cost as first differences. A time-invariant regressor has no within variation (\(x_{it}-\bar x_i=0\)), so demeaning annihilates it exactly as differencing does — its coefficient is not estimable. Neither over-time estimator escapes this. (Random effects, Part IV, is what brings those regressors back.)
  • This is the fixed-effects estimator. Part III develops it — its dummy-variable form, its variance, two-way effects.

Within, between, total: one decomposition

The three estimators are tied together by an identity on the sums of squares. With overall means \(\bar{\bar{\mathbf x}}\), \[\mathbf S_{xx}^{\text{total}}=\mathbf S_{xx}^{\text{between}}+\mathbf S_{xx}^{\text{within}}, \qquad \mathbf S_{xy}^{\text{total}}=\mathbf S_{xy}^{\text{between}}+\mathbf S_{xy}^{\text{within}}.\] Hence pooled OLS is a matrix-weighted average of the between and within estimators: \[\mathbf b^{\text{total}}=\mathbf F^{\text{within}}\mathbf b^{\text{within}}+\mathbf F^{\text{between}}\mathbf b^{\text{between}},\qquad \mathbf F^{\text{within}}=\mathbf I-\mathbf F^{\text{between}}.\]

  • Total variation splits cleanly into cross-sectional (between) and over-time (within) parts — and so does the estimator built from it.
  • Pooled OLS mixes both sources. That is precisely why it is contaminated when \(\alpha_i\) (a between-unit object) is correlated with \(\mathbf x\): the between piece drags in the bias.
  • The escape is to keep only the within piece — the fixed-effects estimator, Part III. Random effects will instead choose the efficient weighting of the two (Part IV).

Part III · Fixed effects

Fixed effects: the default, and its one assumption

The within estimator of Part II is the fixed-effects estimator — \(\hat\bbeta_{FE}=\hat\bbeta_{\text{within}}\). Its robustness (killing \(\alpha_i\) with no restriction on \(\Cov(\alpha_i,\mathbf x_{it})\)) is why it is the default when correlated heterogeneity is a worry. It is not assumption-free, though.

  • The one assumption FE still needs: strict exogeneity conditional on \(\alpha_i\) — \(\E[\varepsilon_{it}\mid\mathbf x_{i1},\dots,\mathbf x_{iT},\alpha_i]=0\): the idiosyncratic error is uncorrelated with past, present and future regressors. Demeaning does not rescue a violation of this (Part VI).
  • What the robustness costs: the between variation — hence the coefficients on time-invariant regressors. FE trades efficiency and those coefficients for consistency under correlated \(\alpha_i\).
  • Next: the dummy-variable view (LSDV) and why it is the same estimator — FWL again.

Within \(\equiv\) LSDV, via FWL

Where does the heterogeneity live? In a unit-specific intercept — each unit sits at its own level \(\alpha_i\). Nothing ties the \(\alpha_i\) across units, so the honest move is to treat each as a free parameter to estimate. A dummy for every unit does exactly that: in the least-squares dummy-variable (LSDV) model the \(i\)-th column of \(\mathbf D\) switches on for unit \(i\), so its coefficient \(\alpha_i\) is that unit’s own intercept — \[\mathbf y=\mathbf D\boldsymbol\alpha+\mathbf X\bbeta+\boldsymbol\varepsilon \qquad(n\text{ intercepts}+K\text{ slopes}).\] With \(n\) in the thousands \(\mathbf D\) is enormous — but we only want \(\bbeta\), and FWL (Lecture 3) says to partial the dummies out first. Partialling them out — applying \(\mathbf M_{\mathbf D}=\mathbf I-\mathbf D(\mathbf D'\mathbf D)^{-1}\mathbf D'\) — is exactly subtracting each unit’s mean, i.e. demeaning: \[\hat\bbeta_{LSDV}=(\mathbf X'\mathbf M_{\mathbf D}\mathbf X)^{-1}\mathbf X'\mathbf M_{\mathbf D}\mathbf y =(\ddot{\mathbf X}'\ddot{\mathbf X})^{-1}\ddot{\mathbf X}'\ddot{\mathbf y}=\hat\bbeta_{\text{within}}.\]

  • The dummy-variable regression and demeaning are the same regression. \(\mathbf M_{\mathbf D}\), the annihilator of the unit dummies (Lecture 3), is the within transformation — so “put in \(n\) intercepts” and “subtract unit means” return the identical \(\hat\bbeta\). FWL, one more time.

LSDV and within: the payoff

One estimator, two readings — and the equivalence buys us two concrete things.

  • LSDV makes the idea concrete — every unit its own intercept; within makes it computable — just subtract means. Same \(\hat\bbeta\), same residuals, either way.
  • The unit effects come back for free. You never carry the \(n\) dummies through the regression: with \(\hat\bbeta\) from the demeaned fit, each unit’s level is recovered after the fact as \[\hat\alpha_i=\bar y_i-\bar{\mathbf x}_i'\hat\bbeta_{FE}.\]
Researcher's Toolbox—Under the hood

Why feols / reghdfe absorb millions of fixed effects without inverting a huge matrix: they never form \(\mathbf D\) — they just demean (iteratively alternating over units and periods for two-way effects). FWL turned an impossible inversion into a subtraction.

Researcher's Toolbox—A degrees-of-freedom trap

Demeaning spends \(n\) degrees of freedom — one unit-mean each — so the honest residual count is \(nT-n-K\), not \(nT-K\). The \(n\) intercepts you “never estimated” reappear exactly here: software that demeans must add back the \(-n\), or the SE comes out too small.

Two-way fixed effects: adding time

Units are not the only source of common, unobserved shocks — a recession, a nationwide reform, a price spike hits everyone in period \(t\). Add a time effect \(\gamma_t\): \[y_{it}=\mathbf x_{it}'\bbeta+\alpha_i+\gamma_t+\varepsilon_{it}.\]

  • Two-way FE sweeps out both fixed unit differences (\(\alpha_i\)) and common time shocks (\(\gamma_t\)) — demean over units and over periods. It is the workhorse behind difference-in-differences (Part VII).
  • Implementation: add \(T-1\) time dummies, or demean iteratively. Identification now needs variation within a unit and within a period — a regressor that moves only with calendar time (a national policy with no cross-sectional variation) is absorbed by \(\gamma_t\).
  • Richer trends are possible — unit-specific linear trends \(t\cdot\alpha_i\) — at the cost of more within variation spent.

Fixed effects or first differences?

Both kill \(\alpha_i\) and use only within variation, and at \(T=2\) they coincide. For \(T>2\) they differ, and the choice is about the error structure.

  • FE (within) is efficient if \(\varepsilon_{it}\) is i.i.d. — serially uncorrelated, homoskedastic. Then demeaning is the right transform.
  • FD is better if \(\varepsilon_{it}\) is close to a random walk — then differencing removes the serial correlation, while FE leaves it.
  • In practice: report FE with cluster-robust SEs (robust to the choice either way); use the FE–FD gap as an informal specification check — a large gap warns of a violated assumption.

Part IV · Random effects

The error-components model

Now assume \(\alpha_i\) (write it \(u_i\)) is uncorrelated with \(\mathbf x_{it}\): \(\E[u_i\mid\mathbf X_i]=0\). Throwing away the between variation (as FE does) is then wasteful. Keep it, and treat the composite error \(\eta_{it}=u_i+\varepsilon_{it}\) as having an equicorrelated structure within each unit: \[\boldsymbol\Sigma=\E[\boldsymbol\eta_i\boldsymbol\eta_i']=\sigma_\varepsilon^2\mathbf I_T+\sigma_u^2\,\mathbf i_T\mathbf i_T', \qquad \boldsymbol\Omega=\mathbf I_n\otimes\boldsymbol\Sigma.\]

  • Every pair of periods in a unit shares \(u_i\), so \(\Cov(\eta_{it},\eta_{is})=\sigma_u^2\) for \(t\neq s\): constant, positive within-unit correlation.
  • \(\boldsymbol\Omega\) is known up to two scalars (\(\sigma_\varepsilon^2,\sigma_u^2\)) and block-diagonal across units — a textbook generalized regression model.
  • So the efficient estimator is GLS (Lecture 7), not OLS. Pooled OLS, FE, FD and between are all consistent here but inefficient — they ignore this known covariance.

Random effects as GLS: quasi-demeaning

GLS is OLS on \(\boldsymbol\Sigma^{-1/2}\)-transformed data, and here the transform is a partial demeaning — subtract only a fraction \(\theta\) of the unit mean: \[y_{it}-\theta\,\bar y_i=(\mathbf x_{it}-\theta\,\bar{\mathbf x}_i)'\bbeta+(\cdots), \qquad \theta=1-\frac{\sigma_\varepsilon}{\sqrt{\sigma_\varepsilon^2+T\sigma_u^2}}.\]

  • \(\theta\) interpolates between the estimators you already know. \(\theta=0\) (no demeaning) is pooled OLS; \(\theta=1\) (full demeaning) is fixed effects. RE demeans just enough to remove the within-unit correlation in the error.
  • When does RE lean toward FE? As \(T\sigma_u^2\) grows (big unit effects, long panels), \(\theta\to1\); when \(\sigma_u^2\to0\), \(\theta\to0\) and RE \(\to\) pooled.
  • The payoff: RE is more efficient than FE and recovers the coefficients on time-invariant regressors (both lost by full demeaning). The price is the assumption \(\Cov(\alpha_i,\mathbf x_{it})=0\) — which Hausman will test.

Feasible GLS: estimating the variance components

\(\theta\) depends on the unknown \(\sigma_\varepsilon^2,\sigma_u^2\), so we estimate them first, then run GLS with \(\hat\theta\) — a feasible GLS two-step.

  • \(\hat\sigma_\varepsilon^2\) from within: demeaning removes \(u_i\), so the within (LSDV) residual variance estimates the idiosyncratic part: \(\hat\sigma_\varepsilon^2=s^2_{LSDV}\).
  • \(\hat\sigma_u^2\) by subtraction: pooled OLS leaves both components in, so \(\plim s^2_{\text{pooled}}=\sigma_\varepsilon^2+\sigma_u^2\). Hence \(\hat\sigma_u^2=s^2_{\text{pooled}}-s^2_{LSDV}\) (floored at \(0\)).
  • Then form \(\hat\theta\), quasi-demean, and OLS. Inference is the GLS covariance; for safety, cluster-robust SEs remain available if the equicorrelation structure is only approximate.

Part V · Choosing between them: the Hausman test

FE or RE? Consistency vs. efficiency

The two estimators trade off consistency against efficiency:

\(\Cov(\alpha_i,\mathbf x_{it})=0\) (RE valid) \(\Cov(\alpha_i,\mathbf x_{it})\neq0\)
FE (within) consistent, inefficient consistent
RE (GLS) consistent, efficient inconsistent

So under \(H_0:\Cov(\alpha_i,\mathbf x_{it})=0\) the two should agree; a large gap is evidence against RE.

  • FE is the safe choice — consistent in both columns. RE is the efficient choice, but only in the left column.
  • The test compares them. If RE’s extra assumption is true, \(\hat\bbeta_{FE}\) and \(\hat\bbeta_{RE}\) estimate the same thing and differ only by noise; if false, they diverge systematically.
  • Decision: a big, systematic gap → reject RE → use FE; a small gap → keep RE (efficiency, and time-invariant regressors).

The Hausman statistic

\[\mathbf H=(\hat\bbeta_{FE}-\hat\bbeta_{RE})'\big[\Var(\hat\bbeta_{FE})-\Var(\hat\bbeta_{RE})\big]^{-1}(\hat\bbeta_{FE}-\hat\bbeta_{RE})\ \dto\ \chi^2_{K}.\]

  • Why the variance is a difference (Hausman’s trick): the covariance of an efficient estimator with its difference from an inefficient one is zero — otherwise you could combine them and beat efficiency (the Cramér–Rao instinct, Lecture 12). So \(\Var(\hat\bbeta_{FE}-\hat\bbeta_{RE})=\Var(\hat\bbeta_{FE})-\Var(\hat\bbeta_{RE})\): no cross term to estimate.
  • Degrees of freedom = number of coefficients compared (time-varying regressors only; the time-invariant ones are not identified by FE).
  • Caveat & decision: the variance difference need not be positive-definite in finite samples (software uses an asymptotically equivalent form). Reject \(H_0\) → correlation → FE; fail to reject → RE is not contradicted.
Researcher's Toolbox—Why we usually report FE anyway — even when Hausman does not reject

(1) Credibility — RE needs \(\Cov(\alpha_i,\mathbf x_{it})=0\), but correlated heterogeneity is the very reason we reached for panel data; assuming it away is usually implausible. (2) The test is weak — “fail to reject” is not “accept”; Hausman has low power, so it often misses a correlation that is really there. (3) Asymmetric stakes — RE buys a modest efficiency gain but risks inconsistency; FE is consistent either way. Use RE mainly when you need time-invariant coefficients — then consider Hausman–Taylor or the Mundlak device (add the unit means \(\bar{\mathbf x}_i\) to RE: it reproduces FE and exposes the very correlation RE assumes away).

Part VI · Fixed effects in practice

Matched designs: twin fixed effects

Fixed effects work for any grouping that shares an unobserved confounder — not only units-over-time. A matched pair is a group of size two.

  • Black, Devereux & Salvanes (2007): does better birth health raise human capital? Regress an outcome on health with a twin fixed effect \(\gamma_j\): \(y_{ij}=\bbeta\,health_{ij}+\gamma_j+\varepsilon_{ij}\).
  • \(\gamma_j\) absorbs everything common to twins — family background, genes, mother’s environment — so identification is from within-pair differences in birth health.
  • The identifying assumption, stated plainly: conditional on the twin FE, the only relevant difference between twins is birth health. Same logic as unit FE — restrict comparisons to within the group.
  • Other examples: siblings, school FE in student data, firm FE in worker–firm data — any hierarchy with a shared latent factor.

What fixed effects do not solve

Fixed effects remove time-invariant confounders. They are not a cure-all — and selling them as one is a common error.

  • Example: murder rate on police spending with city FE. \(\hat\bbeta_{FE}\) is consistent only if \(\varepsilon_{it}\) is uncorrelated with past, present and future \(\mathbf x\) — strict exogeneity conditional on \(\alpha_i\).
  • Violation 1 — time-varying omitted variables. A local crime wave that raises spending and murders is not fixed over time, so FE leaves it in. Bias remains.
  • Violation 2 — simultaneity / reverse causality. If spending responds to murders (cities react to crime), \(\mathbf x_{it}\) is correlated with \(\varepsilon_{it}\) — FE cannot fix it; you need IV or a design.
  • The lesson: fixed effects do not obviate the need for good research design. They buy you freedom from fixed confounders, nothing more.

Part VII · Difference-in-differences

Two groups, two periods

The cleanest use of two-way fixed effects. A policy switches on for a treated group (\(Treat_i=1\)) in the post period (\(Post_t=1\)); a control group never gets it. One regression with the interaction: \[y_{it}=\beta_0+\beta_1\,Post_t+\beta_2\,Treat_i+\delta\,(Post_t\times Treat_i)+\varepsilon_{it}.\]

A wide table showing the predicted outcome in each Treatment-by-Post cell, the post-minus-pre difference for each group, and the difference between those differences, which equals delta.

Writing the predicted mean in each of the four cells and taking the two differences, everything cancels except \(\delta\): the difference of the differences.
  • \(\beta_2\) removes that treated units may start different; \(\beta_1\) removes the common time shift; the interaction \(\delta\) is what is left — the average treatment effect.
  • With panel notation this is just two-way FE: \(\beta_2\!\leadsto\!\alpha_i\) (unit effects), \(\beta_1\!\leadsto\!\gamma_t\) (time effects), and \(\delta\) on \(Treat_i\times Post_t\).

A clean application: Duflo (2001)

Indonesia built 61,000 schools (1973–78), more intensively where more children were out of school. Children young enough to attend (aged 2–6 in 1974) were exposed; older children (12–17) were not. Two differences — region intensity × cohort — give a DiD with no regression.

A two-by-two table titled Intensity of the Building Program. Rows are the young cohort aged 2 to 6 and the older cohort aged 12 to 17; columns are High and Low intensity. Differences are 0.47 and 0.36; the difference-in-differences is 0.12 with standard error 0.089.

The older cohort is the control — same regions, too old to benefit — so its High−Low gap (0.36) is the counterfactual for the young cohort’s (0.47). DiD \(=0.47-0.36=0.12\) extra years of schooling, from the program.
  • The design, not a model, does the work — a transparent double difference, which a two-way FE regression then scales to all regions, cohorts and controls (the DiD coefficient \(\gamma\) on \(P_j\times T_i\)).

Duflo: falsification and dynamics

The transparent design makes its assumptions checkable — the two robustness moves every credible DiD now reports.

A placebo difference-in-differences plot for cohorts that should show no effect; the estimated difference is near zero.

Placebo: a DiD on cohorts too old to benefit returns ≈0 — no spurious effect.

Program effect estimated separately per birth cohort; near zero for older cohorts and increasing for younger, exposed cohorts.

Effect by cohort: ≈0 for cohorts too old, rising for the exposed young cohorts — an event study in age.
  • Placebo (left): run the same DiD on groups you know were unaffected (older cohorts). A non-zero estimate would reveal a confound; here it is ≈0.
  • Effect per cohort (right): estimate \(\delta\) separately by birth year — flat for the unexposed, rising for the exposed. It is the event study in cohort form, and it supports the identifying assumption. Result: +0.12–0.19 years of schooling, +2.6–5.4% wages per school per 1000 children.

Threats, extensions, and the frontier

  • Threats to parallel trends: differential trends (groups already diverging), and compositional change (differential attrition that alters who is in each group).
  • Guard with pre-periods. Several pre-treatment periods make the event-study check convincing — one pre-period proves little.
  • Richer designs: add a third difference (triple-diff, e.g. an eligible vs. ineligible age group within treated vs. control states) to net out group-specific trends.
  • A deeper issue, when adoption is staggered (units switch on at different dates): two-way FE itself can misbehave. That is the modern DiD literature — the next part.

Part VIII · Modern difference-in-differences

When adoption is staggered

Textbook DiD has one treatment date. Real policies roll out unit by unit over years — states adopt a law at different times. The natural generalisation is two-way fixed effects with a staggered indicator \(D_{it}=\mathbf 1\{\text{unit } i \text{ treated at } t\}\): \[y_{it}=\alpha_i+\gamma_t+\delta\,D_{it}+\varepsilon_{it}.\] It looks innocent — but \(\hat\delta\) is now a single number summarising many treatments that may bite differently and grow over time.

  • One \(\delta\) for a heterogeneous reality. With common timing and constant effects, \(\hat\delta\) is still the clean 2×2 DiD. Staggering + heterogeneous or dynamic effects breaks that.
  • The question to ask: what comparisons is TWFE making to get \(\hat\delta\)? Once units adopt at different dates, some units are already treated when others switch on — and TWFE will happily use them as “controls”.

What TWFE estimates: Goodman–Bacon

Goodman–Bacon (2021): the staggered TWFE estimate is a weighted average of every possible 2×2 DiD between timing groups — and the weights, fixed by group sizes and timing, need not be positive.

Two horizontal timelines, Group A (early) and Group B (late). Each is untreated (faint) until its adoption date, then treated (coloured). Between A's and B's adoption dates, a clean 2x2 compares treated A with not-yet-treated B. After B's adoption, a forbidden 2x2 compares B with already-treated A, flagged as carrying a negative weight if effects grow.

With two adoption dates, TWFE forms 2×2’s of two kinds. Clean: before B adopts, use B as a not-yet-treated control for A. Forbidden: after B adopts, use A — already treated — as a “control” for B; if A’s effect is still growing, this comparison enters with a negative weight.
  • The decomposition: \(\hat\delta_{\text{TWFE}}=\sum_{\text{pairs}} w_{\text{pair}}\,\widehat{DiD}_{\text{pair}}\), with some \(w_{\text{pair}}<0\).
  • The alarming consequence: every unit’s true effect can be positive and \(\hat\delta\) can still come out zero or negative. The sign itself can mislead — TWFE is answering a different question than “the average effect”.

The modern event study

The event study — one coefficient per period relative to adoption — is the right object (it shows dynamics and lets us check pre-trends). But under staggered timing the naive TWFE event study inherits the same contamination.

  • Why the naive version is not safe: its “controls” include already-treated units, so even the pre-period coefficients can be biased — a spurious pre-trend that is really contamination, or a real pre-trend masked.
  • Dynamics matter: effects usually build up after adoption; a single \(\delta\) averages a growing path into one number, losing the story the event study tells.
  • Read it, but read the robust one. The fix is to estimate the dynamic path from clean comparisons only (never-treated or not-yet-treated controls) — which is exactly what the new estimators deliver.

The heterogeneity-robust toolkit

A wave of estimators rebuilds DiD from clean comparisons, letting effects vary by group and over time. We name and place them — the formal development is Econometria II.

  • Callaway & Sant’Anna (2021): estimate group-time effects \(ATT(g,t)\) (cohort \(g\) adopting at date, outcome at \(t\)) off clean controls, then aggregate with transparent, non-negative weights into an event study or a single number.
  • Sun & Abraham (2021): an interaction-weighted event study — the safe version of the pre-trend plot, immune to the forbidden comparison.
  • Borusyak, Jaravel & Spiess (2024): an imputation estimator — fit \(\alpha_i+\gamma_t\) on untreated observations, predict each treated observation’s counterfactual, average the gaps.
  • The practical rule for this course: run the event study, check pre-trends — and if adoption is staggered, use a heterogeneity-robust estimator, not raw TWFE (did, fixest::sunab, did2s in R).

Part IX · Synthesis

What to take away

  • One question ran the whole block: is the unobserved effect correlated with the regressors? Yes → fixed effects (within, assumption-free, costs the between variation); No → random effects (GLS, efficient, keeps it). Hausman decides.
  • It is all FWL and GLS again. Within \(=\) annihilator \(\mathbf M_{\mathbf D}\) (Lecture 3); RE \(=\) GLS with a block \(\boldsymbol\Omega\) (Lecture 7); cluster SE \(=\) the block sandwich; DiD \(=\) two-way FE. No new machinery — a new data structure.
  • Identification is still an argument. Strict exogeneity for FE, zero correlation for RE, parallel trends for DiD — each a claim about the DGP you must defend, not a number the software tests.
  • The course in one line: estimation is optimisation (M/Z), inference is a sandwich that collapses under the right weight, identification is an assumption you argue. Panel was the last place to see all three at once.

References

References

  • Greene, Econometric Analysis, ch. 11 (Models for Panel Data).
  • Hansen, Econometrics, ch. 17 (Panel Data).
  • Hausman (1978), “Specification Tests in Econometrics”, Econometrica.
  • Black, Devereux & Salvanes (2007), “From the Cradle to the Labor Market? The Effect of Birth Weight”, QJE.
  • Duflo (2001), “Schooling and Labor Market Consequences of School Construction in Indonesia”, AER.
  • Frontier (Econometria II): Callaway & Sant’Anna (2021); Sun & Abraham (2021).