ML Systems Lab Open interactive version →
Advanced 30 min read DiDdifference-in-differencesparallel trendsevent studystaggered DiD

Difference-in-Differences

Parallel trends, event studies, staggered DiD, DiD failures

A city passes a minimum wage law in 2020. You want to know if it reduced employment. Treated group: businesses in the city. Control group: businesses in a neighboring city without the law. Pre-period: 2018–2019. Post-period: 2020–2021. Simple before-after comparison for the treated city would confound the policy effect with COVID-related employment drops that hit both cities.

DiD subtracts the control city's change from the treated city's change: (treated post − treated pre) − (control post − control pre). This removes the common time trend, leaving only the differential change that appeared when treatment was administered.

The parallel trends assumption is the key identifying assumption. In the absence of treatment, the treated group's outcomes would have followed the same trend as the control group. This is untestable in the post-period — the treated city's counterfactual employment trend under no policy is never observed. It can be tested in pre-periods: if treated and control trends were parallel in 2017 and 2018, they were likely to remain parallel in 2020 absent the intervention. Non-zero pre-period effects in an event study — a regression that estimates the treatment effect separately for each time period relative to treatment — are evidence against parallel trends.

Two-way fixed effects (TWFE) regression formalizes this: Y_it = α_i + λ_t + β D_it + ε_it. Unit fixed effects absorb permanent group differences; time fixed effects absorb common trends; β is the DiD estimate. This handles multiple periods and multiple treatment groups simultaneously.

Staggered treatment timing: when different units receive treatment at different times, TWFE produces biased estimates if treatment effects are heterogeneous across groups or time. Early-treated units act as implicit controls for later-treated units during periods when both are treated — but the early-treated units' outcomes already include treatment effects. The Callaway-Sant'Anna and Sun-Abraham estimators restrict the control group to not-yet-treated or never-treated units for each treatment cohort, producing unbiased estimates in staggered designs.

What parallel trends is not: a weak assumption that is always satisfied. Parallel trends fails when treatment was assigned based on pre-period trends (units selected for treatment because their outcomes were deteriorating), when confounding trends affect treated and control groups differently, when anticipation effects let units start reacting before the official treatment date (a foreseeable policy can shift behavior early, showing up as a pre-trend break right before adoption), or when the groups are fundamentally different in character. Always plot pre-period trends and test formally with an event study before reporting a DiD estimate — and if the pre-trend test fails, add unit-specific trends to the regression or switch to a synthetic control that reweights untreated units to match the treated group's pre-period path, rather than reporting the naive DiD anyway.

Key points

Takeaway

DiD requires parallel trends — untestable post-treatment — and in staggered designs TWFE is biased even when parallel trends holds for every cohort, because early-treated units contaminate the control group for later-treated units.

Recap

Check your understanding

Q1. Your DiD estimate shows minimum wage increase reduced employment by 3%. A critic says the two groups had different pre-trends. How do you respond?

Q2. You are evaluating a product feature rolled out to user cohorts in January, March, and May. You plan TWFE DiD with January as treatment group and March/May as controls. Why is this problematic?

Q3. A policy raising fuel efficiency standards was adopted by California in 2005 and no other state. Select the two genuine threats to parallel trends when using other US states as DiD controls.

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →