← Homepage

Case study: Difference-in-Differences — did the program work?

October 10, 2026

Author: Daniel Jordan Viray

Methods case study · synthetic data with a planted true effect of +5 points, so every claim below is checkable against an answer key we wrote ourselves.

The story

State A launches a job-training program in 2020. State B does nothing. We observe county employment rates in both states, every year 2018–2022. Question: did the program raise employment? This is the bread-and-butter setup: one group gets the treatment, one doesn't, and we watch both before and after.

Why the two obvious comparisons fail

Obvious idea 1: look at State A before vs. after. It went 61.59 → 68.83, up 7.24 points. Program works, right? Not so fast — State B also rose, 64.34 → 67.07. Employment was climbing everywhere. Crediting all of A's rise to the program confuses the program with the passing of time [confounding by time trends].

Obvious idea 2: compare A vs. B after the program: 68.83 vs. 67.07, A wins by 1.76. But they started at different levels (61.59 vs. 64.34) — maybe A was always going to differ [baseline differences / selection bias].

Each naive comparison has exactly one hole. Difference-in-differences patches both at once.

The idea: subtract the changes

Before (2018–19)After (2020–22)Change
State A (program)61.5968.83+7.24
State B (no program)64.3467.07+2.73

State A's change minus State B's change: 7.24 − 2.73 = 4.51 points. That's the estimate.

The intuition. State B's change (+2.73) is our best guess for what would have happened in State A without the program [the counterfactual]. We can't observe that world directly — it's the road not taken — so we borrow B's journey as the stand-in. Whatever is left over after subtracting it, we attribute to the program. Two differences, hence the name.

The regression version (same thing, fancier clothes)

employment ~ treated_state + post + treated_state:post

Plain English: start from a baseline, add "are you in State A?", add "is it after 2020?", and then the star of the show — the interaction [Treat × Post coefficient, β₃]: "how much extra change did the treated group get, after?" That coefficient is the 4.51 from the table. The regression just packages it with standard errors: 4.51, 95% CI (3.18, 5.84), p ≈ 0.0000000001. The planted truth was 5.0 — inside the interval.

The one assumption that matters

Intuition: this whole trick works only if, without the program, State A would have kept moving in parallel with State B — the gap between them would have stayed roughly constant [parallel trends assumption]. Look at the plot: 2018–2019, both lines climb about 1 point per year, side by side. That's the assumption, made visible. If A had already been accelerating before 2020, we'd be crediting the program for a trend that was already there.

parallel pre-trends diverging after 2020

Supporting assumptions (the fine print): the program didn't leak into State B [no spillover / SUTVA] — if B's workers joined A's program, B stops being a clean stand-in. The counties are the same kind of places before and after [stable composition]. And the start date is sharp — everyone knows when 2020 began.

Checks along the way

Check 1 — eyeball the pre-trends. The plot above: parallel before 2020, sharp divergence after. If the pre-lines had fanned out, we'd stop right here.

Check 2 — the placebo test [falsification test]. Pretend the program started in 2019 and run the whole machine on 2018–2019 data only — a period where we know nothing happened. Result: estimated effect 0.27, p = 0.80. Correctly finds nothing. If the method hallucinated effects where none exist, we couldn't trust it where we need it.

Check 3 — the planted truth. We wrote the answer key: the true effect is 5.0. The method recovered 4.51 with CI (3.18, 5.84). It found what we hid.

Limitations, honestly

The 30-second version for your boss.
"We wanted to know if State A's training program worked. We couldn't just look at State A before and after, because employment was already rising everywhere — and we couldn't just compare the states afterward, because they started at different levels. So we measured how much each state changed, and subtracted: State B's change is our best guess for what would have happened in A without the program. The leftover difference, about four and a half points, is our estimate of the program's effect. The key judgment call is that the two states were moving in parallel before the program started, which we verified in the earlier years."

The code (now in the code bank)

This study earned its place in the bank: the reusable pieces live in toolkit/did.py — did_2x2, did_regression, placebo_did, plot_group_trends — each verified to reproduce the numbers on this page. The working version is shown below:

import statsmodels.formula.api as smf

# the 2x2 table of means
t = df.groupby(["treated_state", "post"])["employment"].mean().unstack()
did = (t.loc[True, True] - t.loc[True, False]) \
    - (t.loc[False, True] - t.loc[False, False])   # 4.51

# the regression version: the interaction IS the DiD estimate
fit = smf.ols("employment ~ treated_state + post + treated_state:post",
              data=df).fit()
fit.params["treated_state[T.True]:post[T.True]"]   # 4.51

# placebo: pretend treatment began in 2019, pre-period data only
pre = df[df.year <= 2019].copy()
pre["fake_post"] = pre.year >= 2019
smf.ols("employment ~ treated_state + fake_post + treated_state:fake_post",
        data=pre).fit().params["treated_state[T.True]:fake_post[T.True]"]
# 0.27, p = 0.80 -> correctly finds nothing

Full script: scripts/did_case_study.py in the project folder. Data: data/did_synthetic.csv (80 counties × 5 years, planted effect +5).

What's next

Your call. Natural follow-ups: staggered timing (states adopt in different years), the event-study plot (effect year by year instead of one number), or applying DiD to a real dataset where the answer key doesn't exist and the checks have to carry the weight.