Bell Statistics

What is difference-in-differences?

Difference-in-differences estimates an effect by comparing how much a treated group changed against how much an untreated group changed over the same period. Subtracting the second change from the first removes anything that would have affected both.

Also called
DiD, diff-in-diff, double difference
Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

In plain English

You launch something in six markets and sales rise 8%. The naive reading treats zero as the counterfactual, which is almost never right — sales might have risen 5% anyway on seasonality alone. Difference-in-differences fixes that by borrowing a comparison: look at markets that received nothing, measure how much *they* changed over the same window, and subtract. What remains is the change specific to the treated group, and it is a much better estimate of the effect than either single difference.

The name is literal. The first difference is before-versus-after within the treated group, which removes everything permanently distinctive about those markets — their size, their baseline conversion, their customer mix. The second difference is the same before-versus-after in the untreated group, which captures everything that happened to everyone over that period: the season, the economy, a site-wide change, a competitor's promotion. Subtracting the second from the first removes both classes of nuisance at once, which is why the design is so widely used with observational data.

Everything rests on one assumption, and it is worth stating in its exact form: in the absence of treatment, the two groups would have moved in parallel. Not that they were at the same level — the design explicitly allows different baselines — but that their *trends* would have matched. This cannot be verified, because it is a claim about a period that did not happen. What you can do is check whether the trends were parallel before the intervention, over as long a pre-period as you have, which is evidence for the assumption rather than proof of it.

Two failures break it in practice. Selection into treatment: if the six markets were chosen because they were underperforming, or because a regional manager pushed for them, they were already on a different trajectory and the parallel trends assumption is false in a direction you cannot see. And anticipation: if anyone changed behaviour before the official start date — a pre-launch push, retailers stocking up — the pre-period is contaminated and the effect is understated. When treatment assignment is non-random in a way you cannot argue away, synthetic control is usually the better tool, because it builds a comparison group weighted to match the treated unit's history rather than assuming an existing group will do.

Two technical points that bite. Inference on repeated observations of the same units is not standard: outcomes within a market are correlated over time, so ordinary standard errors are badly understated and the errors must be clustered at the treated unit. And with units treated at different times, the classic two-way fixed-effects regression can be biased — sometimes even carrying the wrong sign — because it uses already-treated units as controls for later-treated ones. Modern estimators from the staggered-adoption literature fix this and should be the default whenever the rollout was phased.

The formula

The estimator is four averages, and it is identical to one coefficient in a regression — which is the form to use in practice, because it gives you standard errors and covariates.

The estimator
DiD = ( Ȳ_treat,post − Ȳ_treat,pre ) − ( Ȳ_ctrl,post − Ȳ_ctrl,pre )

Four group means. The first bracket removes what is fixed about the treated group; subtracting the second removes what happened to everyone.

Regression form
Y = β₀ + β₁·treated + β₂·post + β₃·(treated × post) + ε

β₃ is the DiD estimate. Fit it this way to get standard errors, add covariates, and extend to multiple periods — see the two-sample t-test calculator for the simplest two-period case.

The identifying assumption
E[ Y(0)_post − Y(0)_pre | treated ] = E[ Y(0)_post − Y(0)_pre | control ]

Parallel trends in the ABSENCE of treatment. Untestable by construction, since the left-hand side is never observed.

Inference
cluster standard errors at the treated unit

Observations within a market are serially correlated. Ignoring this understates standard errors severely and produces spurious significance with as few as twenty clusters.

Worked example

A four-week out-of-home campaign runs in eight metro areas. Twelve comparable metros receive nothing. Weekly revenue per 100,000 population is measured for twelve weeks before and four weeks during.

Treated metros, pre-period
£4,120 per 100k / week
Treated metros, campaign period
£4,655
Control metros, pre-period
£3,880
Control metros, campaign period
£4,190
Treated change
+£535 (+13.0%)
Control change
+£310 (+8.0%)

DiD estimate = £535 − £310 = £225 per 100k per week, about a 5.5% lift. Clustered 95% CI: £84 to £366.

The naive 13% would have credited the campaign with the whole seasonal rise that lifted every metro; the honest figure is roughly 5.5%. Before believing it, plot the twelve pre-period weeks for both groups: if the treated metros were already pulling away, the assumption is broken and the estimate is inflated by whatever the divergence was. Two further checks earn their keep. The interval is built on clustered standard errors, and with only eight treated clusters it is wide — unclustered errors here would have been perhaps a third of the width and badly overconfident. And a placebo test, running the same estimator on a period before the campaign, should return an effect indistinguishable from zero; if it does not, the design is picking up something other than the campaign.

Common misconceptions

The pre-period trends look parallel, so the assumption is satisfied.
Parallel pre-trends are evidence, not proof — the assumption concerns the post-period, which is unobservable by construction. A shock coinciding with the treatment can break parallelism after a decade of it holding. Treat the pre-trend check as necessary and never sufficient, and pair it with a placebo test on an earlier period.
Difference-in-differences needs the two groups to be similar.
It needs their trends to be similar, not their levels — that is exactly what the first difference removes. A large market and a small one can support a valid DiD provided they move together proportionally. Insisting on matched levels while ignoring trends gets the requirement precisely backwards.
We can run the standard regression even though markets went live in different weeks.
Two-way fixed effects with staggered adoption uses already-treated units as controls for later-treated ones, and can produce a biased estimate — occasionally with the wrong sign — when effects vary over time. Use an estimator built for staggered adoption instead; the difference is often large enough to reverse a conclusion.

Frequently asked questions

How do I test the parallel trends assumption?
Plot both groups over as long a pre-period as you have and look for divergence, then formalise it with an event-study specification that estimates a separate coefficient for each pre-treatment period — all of those should be indistinguishable from zero. Add a placebo test that applies the estimator to a period before the intervention. None of these prove the assumption, but a design that fails any of them should not be trusted.
When should I use synthetic control instead of DiD?
When the treated units were not chosen at random and no existing group is a convincing comparison. DiD needs an untreated group whose trend already matches; synthetic control constructs one by weighting many untreated units to reproduce the treated unit's pre-period path. That makes it the better choice for a small number of treated units — often one — selected for reasons related to their own trajectory.
Why do difference-in-differences standard errors need clustering?
Because repeated observations of the same market are not independent: this week's revenue is highly correlated with last week's. Treating each week as a fresh observation inflates the effective sample size enormously and produces standard errors that can be several times too small. Cluster at the level treatment was assigned — usually the market — and expect the interval to widen considerably, especially with few clusters.

Related terms

  • Causal inference

    Estimating what an action caused by reconstructing what would have happened without it.

  • Confounding variable

    A common cause of both variables — the reason a strong, stable correlation can mean nothing.

  • Geo experiment

    Randomise regions instead of users — the way to test marketing that cannot be hidden from a person.

  • Regression analysis

    Fit a line through the data — and the phrase 'holding everything else fixed' is where the trouble starts.

  • Synthetic control

    Build the comparison group instead of finding one — the method for when you have one treated unit.

Calculate it

  • Two-sample t-test

    Compare the average of two independent groups — plan the sample size, then test the result.

  • Paired t-test

    Before-and-after or matched pairs — size the study on the difference SD, then test it.

  • Correlation test

    Pearson r or Spearman rho, with the Fisher-z interval that says how little a small sample knows.

Knowing the term is the easy part

Applying it to a live measurement problem is the part that goes wrong. If you are designing an experiment, reading a result you do not trust, or trying to work out what your marketing actually caused, that is the work we do.