Lesson 3 of 11

Difference-in-Differences and Parallel Trends

In Lessons 1 and 2 you fought confounding by modelling it: estimate each unit's propensity to be treated, then match or reweight until the groups balance. That works only for confounders you actually measured. But some things you can never put in a model: the local economy, management culture, a hundred quiet differences between one place and another.

Here is a real case where that mattered. On 1 April 1992, New Jersey raised its minimum wage from $4.25 to $5.05 an hour. Neighbouring Pennsylvania left its wage alone. Standard economics predicted New Jersey would shed fast-food jobs. Economists David Card and Alan Krueger measured full-time-equivalent (FTE) employment at hundreds of restaurants in both states, once in February (before) and once in November (after). If you simply compared the two states afterwards you would be fooled, because New Jersey's restaurants were never quite like Pennsylvania's to begin with.

Difference-in-differences (DiD) is the move that rescues this: instead of comparing the two groups, compare their two changes. By the end of this lesson you will be able to:

  • Explain why a naive after-only comparison, and a naive before-after comparison, are each biased
  • Compute the DiD effect two ways: a 2x2 table of means, and one line of lm(y ~ treat*post)
  • State the parallel-trends assumption, and see why it constrains the groups' trends, not their levels
  • Probe parallel trends with pre-policy data, and recognise when DiD is not safe to use

Prerequisites: Lessons 1 and 2 (confounding, potential outcomes, the average treatment effect, and why a naive comparison can mislead); you can fit lm and read its coefficients.

The setup

Two groups, two periods, one number each

Every DiD study has the same skeleton, and ours is the fast-food example. There are two groups: the treated group that got the policy (New Jersey stores) and a control group that did not (Pennsylvania stores). There are two periods: before the policy (February 1992) and after it (November 1992). And there is one outcome measured in each: average FTE employment per store. That gives four numbers, a 2x2 grid, and DiD is built entirely from those four.

Every lesson runs in a fresh R session, so we build the data here. These are simulated stores patterned on the real study: New Jersey restaurants run a little smaller to start, a mild 1992 slowdown pulls employment down in both states, and we plant a true policy effect of +2.75 FTE in New Jersey after the change, so we can later check whether DiD finds it.

RInteractive R
set.seed(2024) n <- 400 # fast-food stores per state state <- rep(c("PA", "NJ"), each = n) # PA = control, NJ = treated treat <- as.integer(state == "NJ") # 1 = New Jersey, 0 = Pennsylvania base <- ifelse(treat == 1, 20.4, 23.3) + rnorm(2 * n, 0, 7) # Feb-1992 FTE per store trend <- -2.1 # economy-wide dip through 1992 (BOTH states) effect <- 2.75 # the TRUE effect of NJ's wage hike (NJ, after) emp <- data.frame( store = rep(1:(2 * n), 2), state = rep(state, 2), treat = rep(treat, 2), post = rep(0:1, each = 2 * n) # 0 = Feb 1992 (before), 1 = Nov 1992 (after) ) emp$fte <- rep(base, 2) + emp$post * trend + emp$post * emp$treat * effect + rnorm(nrow(emp), 0, 2.5) cell <- tapply(emp$fte, list(state = emp$state, post = emp$post), mean) round(cell, 1) #> post #> state 0 1 #> NJ 20.4 20.9 #> PA 23.6 21.5

  

Read the grid slowly. New Jersey went from 20.4 to 20.9 FTE, a whisker up. Pennsylvania went from 23.6 to 21.5, a clear drop of about two. Those four means are the whole dataset now. Everything that follows is a way of subtracting them.