Difference-in-differences (DiD) estimates a causal treatment effect from panel data by comparing the change in outcomes for a treated group against the change for a control group across the same time span:
DiD = [ Ȳ(treat, post) − Ȳ(treat, pre) ]
− [ Ȳ(control, post) − Ȳ(control, pre) ]
This differencing cancels out any fixed, time-invariant gap between the groups and any trend that affects both groups equally — it only needs the parallel trends assumption: absent treatment, the two groups would have moved in parallel. The dashed line is the counterfactual this assumption implies for the treated group: its own pre-period average, shifted by the control group's actual post-period change.
- True treatment effect — the real causal bump added to the treated group from the policy period onward. Compare it to the DiD estimator above.
- Parallel-trends violation — an extra slope applied only to the treated group, active in both pre- and post-periods. Even a small nonzero value breaks the assumption: the pre-trend gap stat turns non-zero and the DiD estimate becomes biased even though the estimator's formula hasn't changed. (With this construction the bias equals the violation slope times the gap between the pre- and post-period midpoints — 5 periods here — so a violation of 1.0 biases the estimate by exactly +5.)
- Noise (σ) — per-observation random scatter, showing DiD is a statistical estimate, not an exact readout.
- Sample size — more observations per period shrink the scatter of individual points around each group's mean trend.
Real-world use: DiD is the workhorse of policy evaluation — minimum-wage changes, program rollouts, natural experiments — precisely because it needs no randomization, only a comparable control group and (approximately) parallel pre-trends.
Same underlying construction as the 3D sibling (verified numerically): drag to pan the scatter plot and scroll/pinch to zoom, exactly like orbiting the 3D camera.