Quant Memo
Advanced

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 YY be the outcome (venue volume), with a subscript for group and a subscript for time period. Let subscript TT denote the treated group (the venue with the fee cut) and CC the control group (a venue with no change). Let subscript 00 denote the period before the change and 11 the period after.

First take the within-group difference across time for each group:

ΔT=YT,1YT,0,ΔC=YC,1YC,0.\Delta_T = Y_{T,1} - Y_{T,0}, \qquad \Delta_C = Y_{C,1} - Y_{C,0} .

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:

τ^DiD=ΔTΔC=(YT,1YT,0)(YC,1YC,0).\hat{\tau}_{DiD} = \Delta_T - \Delta_C = (Y_{T,1} - Y_{T,0}) - (Y_{C,1} - Y_{C,0}) .

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:

Yit=β0+β1Treati+β2Postt+β3(Treati×Postt)+εit.Y_{it} = \beta_0 + \beta_1 \text{Treat}_i + \beta_2 \text{Post}_t + \beta_3 (\text{Treat}_i \times \text{Post}_t) + \varepsilon_{it} .

In plain English: Treati\text{Treat}_i flags whether unit ii is in the treated group at all, Postt\text{Post}_t flags whether the observation is after the policy change, and β3\beta_3, 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.

BeforeAfterChange
Venue T (treated)100121121100=21121 - 100 = 21
Venue C (control)80868680=686 - 80 = 6

The treated venue's own before-after change is ΔT=21\Delta_T = 21. The control venue's own before-after change is ΔC=6\Delta_C = 6. The difference-in-differences estimate is

τ^DiD=216=15.\hat{\tau}_{DiD} = 21 - 6 = 15 .

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 15/100=15%15/100 = 15\% genuine effect, not the naive 21/100=21%21/100=21\% you'd get from looking at venue T alone.

Worked example 2: the regression form with numbers

Using the same data, code Treat=1\text{Treat}=1 for venue T and 00 for venue C, and Post=1\text{Post}=1 for the after period and 00 for before. There are four cells, matching the table above:

TreatPostYFitted by regression
0080β0\beta_0
0186β0+β2\beta_0 + \beta_2
10100β0+β1\beta_0 + \beta_1
11121β0+β1+β2+β3\beta_0 + \beta_1 + \beta_2 + \beta_3

With exactly four data points and four parameters, the regression fits every cell exactly, so we can solve directly: β0=80\beta_0 = 80 (control, before). β2=8680=6\beta_2 = 86 - 80 = 6 (control's own time trend). β1=10080=20\beta_1 = 100 - 80 = 20 (the gap between venues that already existed before treatment). And from the last row,

121=80+20+6+β3    β3=121106=15.121 = 80 + 20 + 6 + \beta_3 \implies \beta_3 = 121 - 106 = 15 .

β3=15\beta_3 = 15, 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 β3\beta_3 as your treatment effect.

C before 80 C after 86 T before 100 T after 121 would-be T if only trend gap above dashed line = DiD effect (15)
Four bars, one per cell of the 2×2 table. The control venue's own rise (80→86) marks the trend that would have applied to the treated venue anyway; the treated venue rose further than that, and the extra height above the projected line is the 15-unit DiD estimate.
time policy change treated counterfactual control DiD effect
Before treatment, treated and control move in parallel. After treatment, the treated line jumps above where it would have gone (the dashed counterfactual, projected from the control's own trend) — that gap is the estimated 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
ShareTwitterLinkedIn