Difference-in-Differences
- #econometrics
- #causal-inference/difference-in-differences
- #treatment-effects
- #parallel-trends
- #policy-evaluation
- #repeated-cross-sections
Difference-in-Differences
Part of: Econometrics Lecture 10 — Applied Econometrics, Dr. Aluma Dembo Previous: Lec_09-Regression Discontinuity Design (RDD) | Next: %%TODO: next lecture%% Key concepts: Difference-in-Differences, Treatment Effect, Counterfactual, Repeated Cross Sections, Average Treatment Effect on the Treated, Parallel Trends Assumption Builds on: Lec_01-Introduction & Treatment Effects, Lec_08-Fixed Effects in Panel Data
Motivation — policy analysis with treatment effects
A policy is enacted to change some outcome . The ==Treatment Effect== for unit is the difference between the outcome with and without the policy:
The fundamental problem of causal inferenceWe can never observe both and for the same unit at the same time. A city is either locked down or not; a person either took the exam or didn't. One of the two potential outcomes is always missing — it is the Counterfactual.
The naive fix — compare the same city before vs after the policy (an Event Study) — fails because other things change over time too: weather, other policies, behaviour. So a before/after gap mixes the policy effect with everything else that moved. DiD is the trick that nets those common time effects out.
The set-up: two groups, two periods
We need:
- a treatment group (gets the policy) and a control group (doesn't), and
- both observed before and after the policy.
Repeated cross-sections are fineWe do not need the same individuals in each period (Panel Data is not required). Each period can be a fresh sample from the population — this is a ==repeated cross-section==. We only need the four group × period averages.
The four sample means of the outcome:
| Before (period 1) | After (period 2) | |
|---|---|---|
| Control | ||
| Treatment |
The DiD estimator
Take the difference of the two differences — hence the name. Two equivalent orders:
What each version says (they give the same number)
- "difference of changes": how much the treatment group moved, minus how much the control group moved over the same window. The control's change is the common time trend we subtract off.
- "difference of gaps": the treatment–control gap after, minus the gap that already existed before. Any fixed level difference between the groups cancels.
The control group's change is our estimate of what would have happened to the treatment group anyway. Subtracting it leaves the part attributable to the policy — the Average Treatment Effect on the Treated (ATT).
Worked example — Card & Krueger (1994), minimum wage
Research question: does raising the minimum wage reduce low-wage employment? In April 1992 New Jersey raised its minimum wage from $4.25 to $5.05; neighbouring Pennsylvania did not.
- Treatment group: fast-food restaurants in New Jersey.
- Control group: fast-food restaurants in Pennsylvania (wage unchanged).
- Before: Feb–Mar 1992. After: Nov–Dec 1992. (Repeated cross-section of restaurants.)
- Outcome: employment = managers + full-time + 0.5 × part-time.
| Before | After | After − Before | |
|---|---|---|---|
| Control (PA) | 23.331 | 21.166 | −2.166 |
| Treatment (NJ) | 20.439 | 21.027 | +0.588 |
type: diff-in-diff
control: 23.331,21.166
treatment: 20.439,21.027
controlName: Pennsylvania (control)
treatmentName: New Jersey (treated)
periods: Before (Feb–Mar 1992),After (Nov–Dec 1992)
yLabel: employment per restaurant
decimals: 2
The famous (and surprising) resultEmployment in NJ rose by ~2.75 relative to the counterfactual. Pennsylvania employment was falling; absent the hike, NJ would likely have fallen too (the dashed line to 18.27). Instead NJ rose — so raising the minimum wage did not destroy jobs here, contradicting the simple competitive-labour-market prediction. The dashed counterfactual is the whole game: we never see it, we assume NJ would have tracked PA.
DiD as a regression (and why we bother)
Sample averages give the point estimate but can't give standard errors or controls. Equivalent regression with two dummies and their interaction:
- if observation is in the after period (else 0) — the time dummy.
- if in the treatment group (else 0) — the group dummy.
- on the interaction is the DiD treatment effect.
Plug the dummies into the four cells and each coefficient maps onto the 2×2 table:
| Before | After | After − Before | |
|---|---|---|---|
| Control | |||
| Treatment | |||
| T − C |
So = base group (control, before), = common time trend, = fixed group gap, and = the DiD effect.
Card & Krueger in Rmydata$d2 <- as.numeric(mydata$period == 2) mydata$dT <- as.numeric(mydata$location == "New Jersey") treat1 <- lm(total_emp ~ d2 + dT + d2:dT, data = mydata)Output:
d2:dT(treat_effect) = 2.754, SE 1.307, , → significant at 5%, same number as by hand, now with inference.
Why use the regression form? Three payoffs
- Statistical significance — you get a standard error and -value on .
- Controls — add covariates (e.g. fast-food chain dummies) to absorb composition differences and tighten the estimate.
- Fixed effects — add group/neighbourhood Fixed Effects to weaken parallel trends to conditional parallel trends. With many groups and periods this is exactly Two-Way Fixed Effects (see Lec_08-Fixed Effects in Panel Data and PS_04-Seatbelt Laws & Traffic Fatalities).
Validity of a DiD design
DiD is only causal if the control group is a valid counterfactual — it must represent what the treatment group would have done without the policy. Three things to check:
- No coincident shock to the control group. Nothing else should hit the control around treatment time. (If Pennsylvania changed its own tipping law in the after period, would capture NJ's wage hike and PA's tipping law.)
- Comparability. The groups should be broadly similar. (If NJ restaurants are all drive-throughs and PA all sit-down, their employment behaves differently and they aren't comparable.)
- Parallel trends — the big one. Before treatment, the two groups must have moved in parallel. If NJ employment was already trending up faster than PA before the hike, the post gap would have widened anyway and DiD would mistake that trend for a policy effect.
type: parallel-trends
Parallel trends is an assumption, not a factYou can't prove it (the post-period counterfactual is unobserved), but you can make it believable: plot multiple pre-periods and check the lines move together. Non-parallel pre-trends are the classic DiD killer.
Extensions (named, for awareness)
- Staggered roll-out (treatment turns on at different times across units) → use the Bacon Decomposition to diagnose the naive two-way FE estimate.
- Placebo Test — test for a "treatment effect" in a pre-period where none should exist; a non-zero placebo flags broken parallel trends.
- Triple Differences (DDD) — add a third difference (e.g. an extra comparison group) to net out a confounding trend.
Recitation — Kiel & McClain (1995), garbage incinerator
Did the announcement of a garbage incinerator in North Andover, MA depress nearby house prices?
- Repeated cross-section of house sales. Before: 1978 (
y81=0, pre-rumour). After: 1981 (y81=1, rumour confirmed). - Treatment: house within 3 miles of the site (
nearinc=1); control: farther away (nearinc=0). (Different houses each year → repeated cross-section, not a panel.) - Concern: near and far homes already differ (a simple before/after on near homes is not enough) — hence DiD.
The problem set walks through: (1) manual 2×2 DiD on rprice; (2) the regression replication with y81 + nearinc + y81:nearinc; (3) a log-level model — interpret as an approximate % effect; (4) adding continuous house controls; (5) adding neighbourhood fixed effects.
Why does the estimate move when controls are added?The bare 2×2 already differences out fixed level differences between near and far homes (e.g. near homes being older) — those alone don't bias DiD. It does not difference out (a) composition shifts across periods in a repeated cross-section, or (b) trends correlated with house characteristics. Both threaten unconditional parallel trends. Adding controls + neighbourhood FE weakens the requirement to conditional parallel trends (parallel within strata of ).
Summary — Lecture 10
- The fundamental problem of causal inference: we never see a unit's treated and untreated outcome → we need a counterfactual.
- DiD = (treatment change) − (control change). The control's change is the counterfactual trend; subtracting it removes common time shocks and fixed group gaps.
- It works on repeated cross-sections — same individuals not required.
- As a regression, the DiD effect is the coefficient on the time × group interaction — giving significance, controls, and FE.
- Validity hinges on parallel trends (plus no coincident control-group shock, plus comparability). Parallel trends is assumed, made credible by inspecting pre-trends.
- The DiD estimand is the ATT — the effect on the treated.
Related Notes
- Previous: Lec_09-Regression Discontinuity Design (RDD)
- Foundational: Lec_01-Introduction & Treatment Effects · Lec_08-Fixed Effects in Panel Data (DiD = two-way FE)
- Applied: PS_04-Seatbelt Laws & Traffic Fatalities (staggered DiD via two-way FE) · PP_01-Emotions & Risky Choice (Practice Exam) (exam Q3 is a DiD)
- Concepts: Difference-in-Differences · Parallel Trends Assumption · Average Treatment Effect on the Treated · Counterfactual · Repeated Cross Sections
- Hub: Econometrics