Difference-in-Differences
A way to measure the effect of a policy or event by comparing how much a treated group changed before-to-after against how much an untreated group changed over the same window, so that anything moving both groups equally cancels out.
Prerequisites: Ordinary Least Squares (OLS), Panel Data and Fixed Effects
An exchange cuts trading fees on one of its venues but leaves everything else unchanged. Volume on that venue rises 15% over the following month. Did the fee cut cause the increase? You can't just look at the before-and-after change, because plenty of other things also moved that month — overall market volatility picked up, a big index rebalance happened, and total trading activity across every venue was elevated. If you only look at the one venue, you can't separate "the fee cut worked" from "the whole market was busier." What you need is a second venue that didn't get the fee cut, to tell you how much of that 15% would have happened anyway.
An analogy: two patients, one medicine
Imagine testing whether a new medicine lowers blood pressure, but you can't run a randomized trial — you can only observe one patient who happens to be taking it and one who isn't, both measured before and after. If you just look at how much the treated patient's blood pressure dropped, you're also picking up anything else that happened in that time: they might have started exercising, or it might be a seasonal effect that lowers everyone's blood pressure a little in the same weeks.
The fix is to also track the untreated patient over the identical period. Whatever change they show — the exercise trend, the seasonal effect — is a stand-in for "what would have happened to the treated patient without the medicine." Subtract the untreated patient's change from the treated patient's change, and what's left is a cleaner estimate of the medicine's own effect. That subtraction, done twice — once across time, once across groups — is the whole idea behind difference-in-differences.
The estimator, one symbol at a time
Let be the outcome (venue volume), with a subscript for group and a subscript for time period. Let subscript denote the treated group (the venue with the fee cut) and the control group (a venue with no change). Let subscript denote the period before the change and the period after.
First take the within-group difference across time for each group:
In plain English: how much did the treated venue change, and how much did the control venue change, each measured before-to-after on its own.
Then take the difference of those differences:
In plain English: subtract the control group's own change from the treated group's own change — whatever moved both groups equally (the general market trend) cancels out, leaving an estimate of the effect specific to the treated group.
This whole idea can also be written as a single regression with an interaction term, which is how it's usually implemented in practice:
In plain English: flags whether unit is in the treated group at all, flags whether the observation is after the policy change, and , the coefficient on their product, is exactly the difference-in-differences estimate — it's the extra jump the treated group gets in the post period, over and above what being "treated" or being "post" contribute on their own.
The entire method rests on one assumption that can't be tested directly with post-period data: parallel trends — that, absent the fee cut, the treated venue's volume would have moved in lockstep with the control venue's. You build confidence in this by checking that both groups were already trending together before the change.
Worked example 1: the 2×2 table by hand
Two venues, average daily volume in millions of shares, measured in the month before and the month after venue T cuts fees.
| Before | After | Change | |
|---|---|---|---|
| Venue T (treated) | 100 | 121 | |
| Venue C (control) | 80 | 86 |
The treated venue's own before-after change is . The control venue's own before-after change is . The difference-in-differences estimate is
So of the 21-million-share increase at venue T, only 15 million is attributable to the fee cut — the other 6 million would likely have happened anyway, since it happened at the untreated venue too. Expressed as a percentage of venue T's baseline, this is a genuine effect, not the naive you'd get from looking at venue T alone.
Worked example 2: the regression form with numbers
Using the same data, code for venue T and for venue C, and for the after period and for before. There are four cells, matching the table above:
| Treat | Post | Y | Fitted by regression |
|---|---|---|---|
| 0 | 0 | 80 | |
| 0 | 1 | 86 | |
| 1 | 0 | 100 | |
| 1 | 1 | 121 |
With exactly four data points and four parameters, the regression fits every cell exactly, so we can solve directly: (control, before). (control's own time trend). (the gap between venues that already existed before treatment). And from the last row,
, identical to the 2×2 table calculation — confirming that the interaction coefficient in the regression is exactly the difference-in-differences estimator, just derived through a different piece of arithmetic. In a real panel with many venues and many time periods, this regression form is what lets you add fixed effects and controls while keeping as your treatment effect.
What this means in practice
Difference-in-differences is the workhorse for evaluating any policy, rule change, or event that hits one identifiable group and spares a comparable one: a tick-size pilot on some stocks but not others, a short-selling ban in one country, a fee schedule change on one exchange, a tax law affecting some firms. Quants use it in event studies, market-structure research, and regulatory-impact analysis. It requires genuine panel data — the same units, or comparable ones, observed both before and after — and it lives or dies on whether you can defend parallel trends, usually by plotting several pre-periods and checking the lines were already moving together, discussed further in event study methodology.
Difference-in-differences removes anything that would have happened to both groups anyway by subtracting the control group's own before-after change from the treated group's before-after change. The entire credibility of the estimate rests on the parallel trends assumption — that the two groups were on the same trajectory before treatment — which you argue for with pre-trend evidence, never prove outright.
The classic mistake is picking a control group that looks similar on average but was never on a parallel trend — for instance, comparing a small-cap venue against a large-cap one when the two respond differently to market volatility regardless of any fee cut. If pre-treatment trends were already diverging, the post-treatment gap you measure is partly that pre-existing divergence continuing, not the treatment effect. Always plot multiple pre-periods before trusting a two-period DiD estimate — a single before/after snapshot cannot reveal a diverging trend that was already in motion.
Related concepts
Practice in interviews
Further reading
- Angrist & Pischke, Mostly Harmless Econometrics, ch. 5
- Cunningham, Causal Inference: The Mixtape, ch. 9