Panel Data Difference-in-Differences (Panel DiD / TWFE)

Statistics
Introduced by
Ashenfelter & Card (1985); codified by Angrist & Pischke (2009); serial correlation critique by Bertrand, Duflo & Mullainathan (2004)
Year
1985–2004
Type
Causal inference / panel regression
Family
Quasi-experimental / causal inference

What does it do?

Panel Data Difference-in-Differences extends the two-period DiD design to settings where multiple units are observed across many time periods.

Including unit fixed effects and time fixed effects in the same regression isolates the effect of a treatment or policy change from time-invariant unit differences and from common shocks that affect all units. The identifying assumption is parallel trends, which is not directly testable for the post-treatment period.

The intuition behind the method

Imagine tracking many cities over many years. Some cities adopt a new policy at different times; others never do. A naive before-after comparison for treated cities could confound the policy with unrelated economic trends. Panel DiD solves this by using two-way fixed effects: unit fixed effects remove any permanent differences between cities (e.g., geography, culture), and time fixed effects absorb any shocks that hit all cities simultaneously (e.g., recessions). What remains is the within-unit, within-time variation attributable to treatment alone. The control group's trajectory during treated periods serves as the counterfactual for what treated cities would have experienced without the policy.

History

Angrist and Pischke's Mostly Harmless Econometrics (2009) presented the two-way fixed effects approach to difference-in-differences as a standard template for causal panel research. Bertrand, Duflo, and Mullainathan's 2004 Quarterly Journal of Economics paper showed that conventional DiD standard errors understate the true variability of estimates when outcomes are serially correlated; their results helped motivate unit-level clustering, which is now common practice. More recent econometric work has shown that standard TWFE can produce misleading or sign-reversed estimates under staggered adoption with heterogeneous treatment effects, which has prompted the development of heterogeneity-robust estimators.

When to use it

Use Panel DiD when you have a panel of units observed over multiple time periods, a treatment that switches on for some units (simultaneously or at different times) while others serve as controls, and an outcome measured repeatedly for each unit. It suits policy evaluation, labour economics, and health research where administrative panel data are available. Do not use it with only one pre- or post-period (basic DiD is the better design), when all units are treated in the same period (treatment is then collinear with the time effects), when the number of clusters is small enough that clustered inference is unreliable (the limitations list alternatives for few states), or when treatment adoption is driven by outcome trends. With staggered adoption and possibly heterogeneous effects, the TWFE estimate can be a misleading weighted average, so heterogeneity-robust staggered DiD estimators should be considered.

Limitations and considerations

  • The parallel-trends assumption is strong; the post-treatment counterfactual trend cannot be observed, so any divergence in trends after treatment biases the estimate.
  • Standard TWFE can produce misleading estimates under staggered treatment adoption with heterogeneous treatment effects, because already-treated units can enter the comparison as controls, with some implicit weights negative.
  • Requires repeated observations of the same units; cross-sectional data cannot support this design.
  • Inference depends on the number of clusters. When few units are clustered, clustered standard errors can be unreliable even if the total number of observations is large. In the state-level simulations of Bertrand, Duflo, and Mullainathan (2004), a bootstrap that accounts for autocorrelation works well when the number of states is large enough; two corrections based on asymptotic approximations of the variance-covariance matrix work for moderate numbers of states; and a correction that collapses the time series into pre- and post-period observations, with an explicit effective-sample-size adjustment, works even for small numbers of states.
  • Does not handle violations of the stable unit treatment value assumption (SUTVA): spillovers between treated and control units will contaminate the estimate.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Controls simultaneously for unit-level time-invariant confounders and period-level common shocks via two-way fixed effects.
  • Exploits repeated observations of the same units, which can yield more precise estimates than two-period designs when many units and periods are available.
  • Transparent and interpretable: the treatment effect is a single regression coefficient with a clear counterfactual logic.
  • Can accommodate time-varying covariates alongside fixed effects to reduce residual confounding, provided those covariates are not affected by treatment.

Applications

  • Evaluating the effect of labour-market policies (minimum wage laws, job-training programmes) using state or firm panel data.
  • Estimating the impact of educational reforms rolled out across districts or schools at different times.
  • Measuring the health consequences of environmental regulations or public-health interventions using county or hospital panels.
  • Assessing the competitive or financial effects of regulatory changes on firms using firm-year accounting panels.
  • Studying the causal effect of trade liberalisation episodes on productivity, employment, or wages across country or industry panels.
  • Analysing crime or policing policy changes using city- or precinct-level panel data with multiple pre- and post-periods.

How it works

How it works

1

The two-way fixed effects (TWFE) model regresses the outcome on unit fixed effects (α_i), time fixed effects (λ_t), and a treatment indicator D_it that equals 1 for treated units in post-treatment periods. The coefficient δ on D_it is the DiD estimate of the average treatment effect on the treated (ATT). Reading δ as the ATT requires the parallel-trends assumption and, under staggered adoption, homogeneous treatment effects across cohorts and periods (see the limitations). Both sets of fixed effects are absorbed before estimation, leaving only within-unit, within-period variation.

Formula
y_{it} = \alpha_i + \lambda_t + \delta\,D_{it} + \varepsilon_{it}
2

This step defines the estimand, not an estimator: the ATT is the expected difference between the observed outcome and the counterfactual untreated outcome for treated unit-periods. The TWFE coefficient δ is one way to estimate it. Identification requires the parallel-trends assumption, namely that absent treatment, treated and control units would have followed the same time path after conditioning on fixed effects.

Formula
\hat{\delta}_{ATT} = \mathbb{E}[y_{it}(1) - y_{it}(0) \mid D_{it}=1]
3

Before relying on the DiD estimate, inspect pre-treatment trends. A standard approach is to include leads (future treatment indicators) in the event-study specification and examine whether they are jointly insignificant. Jointly insignificant leads are consistent with parallel pre-trends but do not establish them, and significant pre-period differences signal that the parallel-trends assumption is questionable and the estimate may be biased. A passing pre-trend check is therefore supporting evidence to be combined with substantive argument and sensitivity checks, not proof.

4

With panel data, outcomes for the same unit across periods are typically serially correlated. Bertrand, Duflo, and Mullainathan (2004) show that conventional standard errors that ignore this correlation severely understate the sampling variability of DiD estimates. Clustering standard errors at the unit level, or at the level of treatment assignment, is the usual default. Their simulations compare several corrections whose performance depends on the number of clusters, so inference should be checked when few clusters are available.

Common pitfalls

  • Neglecting to cluster standard errors at the unit level, which understates standard errors and overstates significance (Bertrand et al., 2004).
  • Failing to test pre-treatment parallel trends and reporting the DiD coefficient as causal without this diagnostic.
  • Applying the standard TWFE estimator to staggered rollout data without checking for heterogeneous treatment effects; use heterogeneity-robust staggered DiD estimators in that setting.
  • Including time-varying covariates that are themselves affected by treatment (bad controls), which introduces post-treatment bias.
  • Treating a balanced-panel requirement as absolute when unbalanced panels are often usable, without checking whether missingness is related to the outcome.

Frequently asked questions

How does Panel DiD differ from basic two-period DiD?

Basic DiD uses one pre- and one post-period for two groups and relies on a single interaction term. Panel DiD generalises this to many units and many periods, replacing the group and time dummies with full unit and time fixed effects. This absorbs richer heterogeneity and allows testing of parallel pre-trends, but also requires checking for problems specific to multi-period settings, such as serial correlation and staggered-adoption bias.

What is two-way fixed effects (TWFE)?

TWFE is the regression specification underlying Panel DiD. It includes a full set of unit fixed effects (one per panel unit) and a full set of time fixed effects (one per period), together with the treatment indicator. The unit fixed effects remove permanent between-unit differences; the time fixed effects remove period-level shocks common to all units. The treatment coefficient is then identified from within-unit variation over time, net of any common trend.

Why do I need to cluster standard errors?

Bertrand, Duflo, and Mullainathan (2004) emphasise that outcomes for the same unit across years are typically serially correlated, and that conventional DiD standard errors ignore this. In their placebo-law simulations on state-level female wage data, conventional standard errors were far too small: an effect was found significant at the 5 percent level for up to 45 percent of placebo interventions. Clustering at the unit (or treatment-assignment) level is the standard remedy, but its reliability depends on the number of clusters. Bertrand et al. report that a bootstrap accounting for autocorrelation works when the number of states is large enough, that two asymptotic variance corrections work for moderate numbers of states, and that a pre/post collapse with an effective-sample-size correction works even for small numbers of states.

Is Panel DiD valid with staggered treatment timing?

The standard TWFE estimator can be interpreted as a causal effect under staggered timing only if treatment effects are homogeneous across cohorts and periods. When effects are heterogeneous, the TWFE coefficient can be a weighted average of cohort-specific effects in which some weights are negative, which can in principle reverse the sign of the estimate. Heterogeneity-robust staggered DiD estimators, designed to avoid such weights, are generally preferred in heterogeneous settings.

How do I test the parallel-trends assumption?

The standard diagnostic is an event-study plot: include leads (lags of future treatment) and lags (periods after treatment) in the regression and plot their coefficients. If pre-treatment coefficients (leads) are jointly close to zero and statistically insignificant, this is consistent with parallel trends in the pre-period. Note this is a necessary but not sufficient condition: non-rejection does not verify parallel pre-trends, and parallel pre-trends do not guarantee parallel counterfactual trends after treatment.

Related methods

Sources

  1. Angrist, J. D., & Pischke, J.-S. (2009). Mostly Harmless Econometrics: An Empiricist's Companion. Princeton University Press.

    ISBN: 978-0691120355
  2. Bertrand, M., Duflo, E., & Mullainathan, S. (2004). How Much Should We Trust Differences-in-Differences Estimates? Quarterly Journal of Economics, 119(1), 249-275.

    Open DOI reference