Difference-in-differences

On this page 7

Difference-in-differences (often abbreviated DiD or DD) is a quasi-experimental method that estimates a causal treatment effect by subtracting the change over time in an untreated comparison group from the change over time in a treated group. In data experimentation, it is the standard tool when randomization is impossible or incomplete, for example when a feature launches in one market, a policy applies to one region or a price change reaches only some stores.

The method rests on one decisive idea: the comparison group shows what would have happened to the treated group without the intervention. If both groups would have moved in parallel, any extra change in the treated group after the intervention is attributed to the treatment. That assumption, called parallel trends, cannot be proven directly, so most of the analytical work in a credible DiD study goes into defending it.

How difference-in-differences isolates the effect

Difference-in-differences removes two kinds of bias at once by taking two successive differences. The first difference, before versus after, removes stable differences between groups, such as one region always having higher sales. The second difference, treated versus comparison, removes shared time shocks, such as seasonality or a macroeconomic downturn that affects everyone.

The classic two-group, two-period design can be read directly from four group means. The table below shows how the estimate is assembled from them, using an illustrative conversion metric.

GroupBeforeAfterChange
Treated group4.0%5.1%+1.1 points
Comparison group3.6%4.0%+0.4 points
Difference-in-differences0.4 points1.1 points+0.7 points
The two-by-two difference-in-differences calculation

In regression form, the same estimate is the coefficient on an interaction term between a treated-group indicator and a post-period indicator: outcome = a + b·treated + c·post + d·(treated × post) + error. The coefficient d is the DiD estimate, and the regression framework makes it easy to add covariates, compute standard errors and extend the design to many groups and periods.

Assumptions behind a valid estimate

A difference-in-differences estimate is only as credible as its identifying assumptions. The parallel trends assumption is the core one, but several others matter in practice, and each has a typical way of being checked.

AssumptionWhat it requiresTypical check
Parallel trendsGroups would evolve alike without treatmentPlot pre-period trends, event-study leads
No anticipationUnits do not react before the start dateInspect periods just before launch
Stable compositionGroup membership does not shift because of treatmentCompare user counts and mix over time
No spilloverTreatment does not affect the comparison groupChoose geographically or logically separate units
No concurrent shocksNo other change hits only one groupReview release calendars and external events
Key assumptions and how analysts examine them

Parallel trends concern the counterfactual future, so pre-period data can only support the assumption, never confirm it. Similar slopes before treatment make the assumption plausible; diverging slopes are a strong warning sign that the comparison group is unsuitable or that a trend adjustment is needed.

How DiD compares with other experimentation methods

Difference-in-differences sits between a randomized A/B test and purely observational analysis. It borrows the logic of a control group but replaces random assignment with an assumption about trends, which makes it weaker than randomization but far stronger than a naive before-and-after comparison.

MethodSource of comparisonMain vulnerability
A/B testingRandomized control groupSample ratio mismatch, novelty effect
Difference-in-differencesNon-random group plus timeViolated parallel trends
Before-and-after comparisonSame group earlierAny time trend or seasonal shock
Synthetic controlWeighted blend of untreated unitsPoor pre-period fit
Switchback experimentRandomized time slotsCarryover between periods
Difference-in-differences and related designs

Variance reduction techniques such as CUPED share a conceptual root with DiD, because both use pre-period data to remove noise. The difference is purpose: CUPED improves the precision of a randomized test, while DiD supplies the identification when there is no randomization at all.

Extensions for staggered rollouts

Real launches rarely happen in one step, so most production analyses use multi-period DiD with many groups. The traditional approach is the two-way fixed effects regression, which includes a fixed effect for each unit and each period plus a treatment indicator.

Econometric research since about 2018 has shown that two-way fixed effects can produce biased or even wrongly signed estimates under staggered adoption with effects that change over time. The problem arises because already-treated units serve as comparisons for later-treated units. Modern estimators, such as those proposed by Callaway and Sant’Anna, Sun and Abraham, or de Chaisemartin and D’Haultfoeuille, compare each cohort only with not-yet-treated or never-treated units.

  • Event-study plots show the estimated effect for each period relative to treatment and reveal pre-trends as non-zero leads.
  • Triple differences add a third dimension, such as an unaffected product line, to absorb group-specific shocks.
  • Matched DiD pairs treated units with similar comparison units before differencing to make parallel trends more plausible.

Common mistakes and how to avoid them

Most failed DiD analyses fail for a small set of recurring reasons. The table below lists the typical symptoms, their cause and the practical remedy.

MistakeConsequenceRemedy
Ignoring clustered errorsOverstated statistical significanceCluster standard errors by group
Too few groupsUnreliable inferenceUse wild cluster bootstrap or randomization inference
Picking a convenient comparisonHidden selection biasDefine the comparison group before seeing results
Skipping pre-trend reviewUndetected violated assumptionReport an event-study plot
Plain two-way fixed effects with staggered timingBiased average effectUse heterogeneity-robust estimators
Frequent errors in difference-in-differences analysis

Serial correlation deserves special attention. Outcomes measured repeatedly for the same unit are correlated over time, and ignoring this can make p-values far too small. Clustering at the level of treatment assignment, such as the region or store, is the minimum defensible standard.

The simple explanation

Imagine two neighboring towns. One town opens a new park, and you want to know whether people there now walk more. Simply counting walks before and after is misleading, because spring weather alone might make everyone walk more.

So you also watch the second town, which got no park. If walking rose by ten percent in the town without the park and by twenty-five percent in the town with it, the park probably caused the extra fifteen percent. The method works only if both towns would have changed in the same way without the park, which is why careful analysts look at their history first.

How it is used in practice

A food delivery company introduces a new tipping screen in its app, but for legal reasons it must launch in one country at once rather than through a randomized test. The analytics team chooses two neighboring countries with similar order patterns as the comparison group and collects twelve weeks of data before and eight weeks after the launch.

The event-study plot shows flat, near-zero differences in average tip per order during the pre-period, which supports parallel trends. After launch, average tips rise by 0.42 currency units in the launch country and by 0.09 in the comparison countries, giving a DiD estimate of 0.33 units per order. With standard errors clustered by city and a placebo test on a fake launch date showing no effect, the team reports the result as a credible causal estimate and uses it to plan the rollout in further markets.