Difference-in-Differences (DiD) – TWFE

A panel-data Difference-in-Differences estimator for staggered rollouts across many units and many time periods.

Best for: staged launches where units adopt the treatment at different times

What the DiD TWFE method does

Difference-in-Differences with Two-Way Fixed Effects (DiD–TWFE) generalizes the basic DiD idea to panel data with many units and many time periods. Instead of just comparing two time points, TWFE uses all available periods while controlling for:

Intuitively, each unit is compared to itself over time, while TWFE adjusts for global movements that affect all units. The resulting coefficient on treatment is interpreted as an average treatment effect on the treated under standard DiD assumptions.

The DiD TWFE regression

A common TWFE specification is:

Yit = αi + λt + β Dit + εit

where:

When to use DiD – TWFE

DiD TWFE is a good fit when:

Typical examples include:

Core assumptions

1. Parallel trends (conditional on fixed effects)

In the absence of treatment, treated and control units would have followed similar trends over time, after accounting for unit and time fixed effects. Violations of this assumption directly bias the DiD estimate.

2. No anticipation

Units should not change behavior before the recorded treatment time. If they anticipate the rollout and react early, pre‑treatment periods are contaminated and no longer represent true counterfactual behavior.

3. Once treated, always treated (standard TWFE setup)

Classical DiD–TWFE assumes treatment status is monotonic: once a unit becomes treated, it remains treated. When units move in and out of treatment repeatedly, the interpretation of the TWFE coefficient becomes more complicated.

4. No interference between units

Treatment of one unit should not directly change outcomes of another unit (no strong spillovers). Large cross‑unit spillovers break the simple DiD interpretation and may require more specialized designs.

Known issues with naive TWFE

Modern DiD literature has shown that naive TWFE can behave poorly in staggered adoption settings, especially when treatment effects are heterogeneous over time or across cohorts. In particular:

The takeaway: a single TWFE coefficient is not always a reliable summary of the causal effect in a staggered rollout. Diagnostics and alternative estimators are often necessary.

How helps you use TWFE safely

is designed to make DiD TWFE more transparent and safer for data scientists:

Event‑study interpretation

Instead of only reporting one TWFE coefficient, can estimate a sequence of relative time coefficients (an event study):

Yit = αi + λt + Σk ≠ -1 βk 1{event_time = k} + εit

where event_time indexes time relative to treatment (e.g., −3, −2, −1, 0, +1, +2, …). This lets you:

When DiD – TWFE is not a good fit

Consider alternative designs if:

Summary

DiD TWFE is a powerful way to estimate treatment effects in staggered rollouts, but it comes with non‑trivial assumptions and known pitfalls. wraps TWFE in guardrails, diagnostics, and modern DiD tooling so data scientists can: