Skip to main content

Difference-in-Differences: Does a Higher Minimum Wage Cost Jobs?

Difference-in-differences in R on the 410 fast-food restaurants of Card and Krueger: the four means, the same number from a regression, from changes and from two-way fixed effects, clustered standard errors by hand, the parallel trends assumption, comparisons within New Jersey, other outcomes and definitions, how small a difference in trends or a shock to a state changes the conclusion, why controlling for the first value gives another answer, what goes wrong when a treatment comes in waves (two-way fixed effects against group-time effects by hand and with did), and APA reporting.

The question: two states and a law

On 1 April 1992 the minimum wage in New Jersey rose from $4.25 to $5.05 an hour. In Pennsylvania, on the other side of the river, it stayed at $4.25. What happened to the jobs in fast-food restaurants, where many people earn the minimum?

Two simple comparisons come to mind, and both are wrong:

  • New Jersey after against before. But 1992 was a year of recession. Jobs may have changed anyway.
  • New Jersey against Pennsylvania, after. But the restaurants in the two states may have been different from the start.

Difference-in-differences (DiD) combines them. The change in Pennsylvania shows what happened anyway. The change in New Jersey, minus the change in Pennsylvania, is the effect of the law. It is simple enough for a pocket calculator. What it needs is one assumption, and most of this page is about that one.

The study by Card and Krueger (1993, published in the American Economic Review in 1994) is one of the best-known in economics, and one of the most disputed. This page uses it to teach the method. It does not settle the question.

Code
library(ggplot2)
library(fixest)      # feols(): regression with fixed effects and clustered errors
# also used, with package::function: did (att_gt, aggte), quantreg (rq)

# number formats for the text
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
pval <- function(p) {
  ifelse(p < .001, "< .001", paste("=", sub("^0", "", formatC(p, format = "f", digits = 3))))
}
num  <- function(x) trimws(format(x, big.mark = ","))
pct  <- function(x, d = 0) paste0(formatC(100 * x, format = "f", digits = d), "%")

1. The data

Code
zip_file <- tempfile(fileext = ".zip")
download.file(
  "https://davidcard.berkeley.edu/data_sets/njmin.zip",
  zip_file,
  mode = "wb",
  quiet = TRUE
)
data_file <- unzip(zip_file, "public.dat", exdir = tempfile("njmin"))
names_in_codebook <- c(
  "sheet", "chain", "co_owned", "state", "southj", "centralj", "northj", "pa1", "pa2", "shore",
  "ncalls", "empft", "emppt", "nmgrs", "wage_st", "inctime", "firstinc", "bonus", "pctaff", "meals",
  "open", "hrsopen", "psoda", "pfry", "pentree", "nregs", "nregs11", "type2", "status2", "date2",
  "ncalls2", "empft2", "emppt2", "nmgrs2", "wage_st2", "inctime2", "firstin2", "special2", "meals2",
  "open2r", "hrsopen2", "psoda2", "pfry2", "pentree2", "nregs2", "nregs112"
)
stores <- read.table(data_file, col.names = names_in_codebook, na.strings = ".")
stores$id <- seq_len(nrow(stores)) # (one sheet number is used twice)
stores$nj <- stores$state # 1 New Jersey, 0 Pennsylvania
# full-time equivalents, first interview
stores$fte1 <- stores$empft + stores$nmgrs + 0.5 * stores$emppt
stores$fte2 <- stores$empft2 + stores$nmgrs2 + 0.5 * stores$emppt2 # second interview
table(
  state = ifelse(stores$nj == 1, "New Jersey", "Pennsylvania"),
  second_interview = stores$status2
)
              second_interview
state            0   1   2   3   4   5
  New Jersey     1 321   2   5   1   1
  Pennsylvania   0  78   0   1   0   0

Card and Krueger interviewed 410 restaurants of four chains (Burger King, KFC, Roy Rogers, Wendy’s), 331 in New Jersey and 79 in eastern Pennsylvania. The first interview was in February and March 1992, before the law, the second in November and December. The outcome is employment in full-time equivalents (FTE): full-time employees and managers count 1, part-time employees a half. The six restaurants that had closed for good (status 3) have an employment of zero in the second interview. The file is on David Card’s web page.


2. Look at the data

Did the law do anything to the wages? The starting wage in both interviews:

Code
w <- rbind(
  data.frame(state = stores$nj, wage = stores$wage_st, wave = "before"),
  data.frame(state = stores$nj, wage = stores$wage_st2, wave = "after")
)
w$state <- ifelse(w$state == 1, "New Jersey", "Pennsylvania")
w$wave <- factor(w$wave, levels = c("before", "after"))
w <- subset(w, !is.na(wage))
w$share <- ave(w$wage, w$state, w$wave, FUN = function(v) 1 / length(v))
ggplot(w, aes(wage, weight = share, fill = state)) +
  geom_histogram(breaks = seq(4.2, 5.8, by = 0.1), colour = "white") +
  facet_grid(state ~ wave) +
  scale_fill_manual(values = c("#2a78d6", "#eb6834"), guide = "none") +
  scale_y_continuous(labels = scales::percent) +
  labs(
    title = "Starting wages before and after the law",
    x = "starting wage (dollars per hour)",
    y = "share of restaurants"
  ) +
  theme_bw()

Wages chart – 2. Look at the data

Code
wage_means <- with(
  stores,
  rbind(
    `New Jersey` = c(
      before = mean(wage_st[nj == 1], na.rm = TRUE),
      after = mean(wage_st2[nj == 1], na.rm = TRUE)
    ),
    Pennsylvania = c(mean(wage_st[nj == 0], na.rm = TRUE), mean(wage_st2[nj == 0], na.rm = TRUE))
  )
)
round(wage_means, 2)
             before after
New Jersey     4.61  5.08
Pennsylvania   4.63  4.62
Code
at_min <- mean(abs(stores$wage_st2[stores$nj == 1] - 5.05) < 0.001, na.rm = TRUE)

It did. Before, the two states looked the same. After, 89% of the restaurants in New Jersey paid exactly the new minimum, and nothing had changed in Pennsylvania. The mean starting wage rose by 0.47 dollars, or 10%.


3. The model step by step, with formulas

Step 1: four means

\[\widehat{DiD} = (\bar y_{NJ,\text{after}} - \bar y_{NJ,\text{before}}) - (\bar y_{PA,\text{after}} - \bar y_{PA,\text{before}})\]

Code
m <- with(
  stores,
  rbind(
    `New Jersey` = c(
      before = mean(fte1[nj == 1], na.rm = TRUE),
      after = mean(fte2[nj == 1], na.rm = TRUE)
    ),
    Pennsylvania = c(mean(fte1[nj == 0], na.rm = TRUE), mean(fte2[nj == 0], na.rm = TRUE))
  )
)
cbind(m, change = m[, "after"] - m[, "before"])
               before    after     change
New Jersey   20.43941 21.02743  0.5880214
Pennsylvania 23.33117 21.16558 -2.1655844
Code
did_hand <- diff(m["New Jersey", ]) - diff(m["Pennsylvania", ])
c(did = did_hand[[1]])
     did 
2.753606 

In New Jersey a restaurant had 20.44 full-time equivalents before and 21.03 after the law: a small rise. In Pennsylvania employment fell, from 23.33 to 21.17. The difference in differences is +2.75 FTE per restaurant. The textbook theory of the labor market expects a minus.

Step 2: a regression

The same number is the coefficient of the product term in a regression with two indicator variables:

\[y_{it} = \alpha + \beta\,NJ_i + \gamma\,\text{After}_t + \delta\,(NJ_i \times \text{After}_t) + \varepsilon_{it}\]

\(\alpha\) is Pennsylvania before, \(\beta\) the difference between the states before, \(\gamma\) the change in Pennsylvania, and \(\delta\) the DiD. The regression also gives a standard error, but the two interviews of the same restaurant are not independent. So the errors are clustered by restaurant, here by hand:

\[V = \frac{G}{G-1}\,\frac{N-1}{N-K}\,(X^\top X)^{-1}\Big(\sum_g X_g^\top e_g e_g^\top X_g\Big)(X^\top X)^{-1}\]

Code
long <- rbind(
  with(stores, data.frame(id, nj, after = 0, fte = fte1)),
  with(stores, data.frame(id, nj, after = 1, fte = fte2))
)
long <- subset(long, !is.na(fte))
fit <- lm(fte ~ nj * after, long)
X <- model.matrix(fit)
scores <- rowsum(X * residuals(fit), long$id)
G <- nrow(scores)
N <- nrow(X)
K <- ncol(X)
V <- G /
  (G - 1) *
  (N - 1) /
  (N - K) *
  solve(crossprod(X)) %*% crossprod(scores) %*% solve(crossprod(X))
clustered <- feols(fte ~ nj * after, long, cluster = ~ id)
rbind(
  estimate = c(
    lm = coef(fit)[["nj:after"]],
    by_hand = coef(fit)[["nj:after"]],
    feols = coef(clustered)[["nj:after"]]
  ),
  SE = c(
    sqrt(vcov(fit)["nj:after", "nj:after"]),
    sqrt(V["nj:after", "nj:after"]),
    se(clustered)[["nj:after"]]
  )
)
               lm  by_hand    feols
estimate 2.753606 2.753606 2.753606
SE       1.688409 1.306607 1.306607

The usual SE (1.69) is too large here. It does not know that a restaurant is compared with itself.

Step 3: changes, or two-way fixed effects

With two periods one can also take the change of each restaurant and compare the two groups with an ordinary regression. Or give every restaurant and every period its own constant (two-way fixed effects, TWFE, see panel data). For restaurants with both interviews that is the same:

Code
both <- subset(stores, !is.na(fte1) & !is.na(fte2)); both$change <- both$fte2 - both$fte1
change_fit <- feols(change ~ nj, both, vcov = "hetero")
twfe_fit   <- feols(fte ~ nj:after | id + after, subset(long, id %in% both$id), cluster = ~ id)
v_hand <- with(
  both,
  sqrt(var(change[nj == 1]) / sum(nj == 1) + var(change[nj == 0]) / sum(nj == 0))
)
rbind(
  `regression of the changes` = c(estimate = coef(change_fit)[["nj"]], SE = se(change_fit)[["nj"]]),
  `two-way fixed effects` = c(coef(twfe_fit)[["nj:after"]], se(twfe_fit)[["nj:after"]]),
  `two means, by hand` = c(with(both, mean(change[nj == 1]) - mean(change[nj == 0])), v_hand)
)
                          estimate       SE
regression of the changes     2.75 1.337725
two-way fixed effects         2.75 1.337723
two means, by hand            2.75 1.342341

384 of the 410 restaurants have both values, and the result is 2.75 (SE 1.34).

Step 4: the assumption

What is the causal effect? The outcome of New Jersey after the law, minus what it would have been without it. The second part nobody has seen. DiD fills it in: New Jersey would have changed like Pennsylvania. That is the parallel trends assumption:

\[E[y_{\text{after}}(0) - y_{\text{before}}(0) \mid NJ] = E[y_{\text{after}}(0) - y_{\text{before}}(0) \mid PA]\]

(\(y(0)\): employment without the law.)

Code
lines <- data.frame(
  state = rep(c("New Jersey", "Pennsylvania", "New Jersey without the law (assumed)"), each = 2),
  time = rep(0:1, 3),
  fte = c(
    m["New Jersey", ],
    m["Pennsylvania", ],
    m["New Jersey", "before"],
    m["New Jersey", "before"] + diff(m["Pennsylvania", ])
  )
)
ggplot(lines, aes(time, fte, colour = state, linetype = state)) +
  geom_line(linewidth = 1) +
  geom_point(size = 2.6) +
  scale_x_continuous(
    breaks = 0:1,
    labels = c("February 1992", "November 1992"),
    limits = c(-0.1, 1.15)
  ) +
  scale_colour_manual(
    values = c(
      "New Jersey" = "#2a78d6",
      "Pennsylvania" = "#eb6834",
      "New Jersey without the law (assumed)" = "#2a78d6"
    ),
    name = NULL
  ) +
  scale_linetype_manual(
    values = c(
      "New Jersey" = "solid",
      "Pennsylvania" = "solid",
      "New Jersey without the law (assumed)" = "dashed"
    ),
    name = NULL
  ) +
  annotate(
    "segment",
    x = 1.06,
    xend = 1.06,
    y = lines$fte[6],
    yend = lines$fte[2],
    arrow = arrow(length = unit(0.2, "cm"))
  ) +
  annotate("text", x = 1.09, y = mean(lines$fte[c(2, 6)]), label = "DiD", hjust = 0) +
  labs(
    title = "The four means, and what the assumption adds",
    x = NULL,
    y = "full-time equivalents per restaurant"
  ) +
  theme_bw() +
  theme(legend.position = "bottom", legend.direction = "vertical")

Trends chart – Step 4: the assumption

Note where the result comes from. New Jersey hardly moved. The effect is mostly the fall in Pennsylvania, which New Jersey is supposed to have been spared.


4. Reading the output

Code
summary(clustered)
OLS estimation, Dep. Var.: fte
Observations: 794
Standard-errors: Clustered (id) 
            Estimate Std. Error  t value  Pr(>|t|)    
(Intercept) 23.33117    1.34654 17.32681 < 2.2e-16 ***
nj          -2.89176    1.43955 -2.00880  0.045215 *  
after       -2.16558    1.21802 -1.77795  0.076155 .  
nj:after     2.75361    1.30661  2.10745  0.035687 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
RMSE: 9.3819   Adj. R2: 0.003632
Code
ci_did <- confint(clustered)["nj:after", ]

The law is estimated to have raised employment by 2.75 FTE per restaurant, 95% CI [0.19, 5.32], p = .036. That is 13% of the 20.4 before the law. Whether it is a rise or nothing is one question. That the interval excludes a loss is what started the debate.


5. Other ways of looking

More than one comparison

Pennsylvania need not be the only comparison. In New Jersey some restaurants already paid $5 or more. The law meant nothing to them. Card and Krueger used the gap: by how much a restaurant had to raise its starting wage to reach the new minimum.

Code
stores$gap <- with(stores, ifelse(nj == 0, 0, pmax(0, (5.05 - wage_st) / wage_st)))
both$gap <- stores$gap[match(both$id, stores$id)]
gap_all <- feols(change ~ gap, both, vcov = "hetero")
gap_nj <- feols(change ~ gap, subset(both, nj == 1), vcov = "hetero")
both$wage_group <- cut(
  both$wage_st,
  c(0, 4.251, 4.999, 10),
  labels = c("4.25", "4.26 to 4.99", "5.00 or more")
)
within <- with(
  subset(both, nj == 1 & !is.na(wage_group)),
  data.frame(
    starting_wage_before = levels(wage_group),
    restaurants = as.numeric(table(wage_group)),
    mean_before = as.numeric(tapply(fte1, wage_group, mean)),
    mean_change = as.numeric(tapply(change, wage_group, mean)),
    se = as.numeric(tapply(change, wage_group, function(v) sd(v) / sqrt(length(v))))
  )
)
print(data.frame(within[1:2], round(within[3:5], 2)), row.names = FALSE)
 starting_wage_before restaurants mean_before mean_change   se
                 4.25          94       19.44        1.20 0.82
         4.26 to 4.99         132       20.20        0.71 0.69
         5.00 or more          67       22.17       -2.16 1.01
Code
rbind(
  all_restaurants = c(slope = coef(gap_all)[["gap"]], SE = se(gap_all)[["gap"]]),
  new_jersey_only = c(coef(gap_nj)[["gap"]], se(gap_nj)[["gap"]])
)
                   slope       SE
all_restaurants 16.35898 5.984543
new_jersey_only 13.08053 6.713600
Code
mean_gap <- mean(stores$gap[stores$nj == 1], na.rm = TRUE)

In New Jersey, employment changed by 1.20 in the restaurants that paid $4.25, and by -2.16 in those that already paid $5. The slope on the gap (with both states) times the mean gap in New Jersey (0.10) is 1.72 FTE: the same sign as the DiD, and smaller. Two different control groups tell the same story. That is better evidence than one. (But the restaurants that already paid well were also larger before the law, 22.2 FTE against 19.4, like those in Pennsylvania. Section 6 comes back to this.)

Other outcomes, other definitions

Code
change_in <- function(a, b) {
  d <- data.frame(nj = stores$nj, change = b - a)
  f <- feols(change ~ nj, d, vcov = "hetero")
  c(estimate = coef(f)[["nj"]], SE = se(f)[["nj"]], p = pvalue(f)[["nj"]], n = nobs(f))
}
fte_w <- function(weight) {
  change_in(
    with(stores, empft + nmgrs + weight * emppt),
    with(stores, empft2 + nmgrs2 + weight * emppt2)
  )
}
pos <- function(v) ifelse(v > 0, log(v), NA)
open_again <- ifelse(stores$status2 == 3, NA, stores$fte2)
variants <- rbind(
  `FTE, part-time counts 0.5` = fte_w(0.5),
  `FTE, part-time counts 0.25` = fte_w(0.25),
  `FTE, part-time counts 1 (heads)` = fte_w(1),
  `FTE, closed restaurants left out` = change_in(stores$fte1, open_again),
  `log FTE` = change_in(pos(stores$fte1), pos(stores$fte2)),
  `full-time employees` = change_in(stores$empft, stores$empft2),
  `part-time employees` = change_in(stores$emppt, stores$emppt2),
  `hours open per day` = change_in(stores$hrsopen, stores$hrsopen2),
  `starting wage (dollars)` = change_in(stores$wage_st, stores$wage_st2),
  `log price of a full meal` = change_in(
    with(stores, log(psoda + pfry + pentree)),
    with(stores, log(psoda2 + pfry2 + pentree2))
  )
)
round(variants, 3)
                                 estimate    SE     p   n
FTE, part-time counts 0.5           2.750 1.338 0.040 384
FTE, part-time counts 0.25          2.919 1.413 0.040 384
FTE, part-time counts 1 (heads)     2.412 1.487 0.106 384
FTE, closed restaurants left out    2.722 1.335 0.042 378
log FTE                             0.078 0.049 0.111 378
full-time employees                 3.443 1.583 0.030 392
part-time employees                -0.911 1.527 0.551 396
hours open per day                 -0.111 0.102 0.278 399
starting wage (dollars)             0.497 0.051 0.000 370
log price of a full meal            0.029 0.013 0.027 356
Code
median_did <- unname(coef(quantreg::rq(change ~ nj, data = both))[2])
c(difference_of_the_median_changes = median_did)
difference_of_the_median_changes 
                             1.5 
Code
v <- function(name, what) variants[name, what]
  • The result does not depend much on how a part-timer is counted (2.41 to 2.92), nor on the closed restaurants.
  • It does depend on the scale. In logs it is 0.08 (about 8%) with p = .111. Trends that are parallel in numbers are not parallel in logs, and the method cannot tell us which scale is right. The median change differs by 1.5.
  • Prices of a meal rose by 2.9% more in New Jersey (p = .027). The customers paid a part of the law.

6. How far can we trust it?

Two states are two observations

The standard error counted 410 restaurants. But the law was given to states, and there are two. Suppose each state had a shock of its own in 1992 (weather, the local economy), with a standard deviation \(\sigma\) in the change per restaurant. Then the variance of the DiD is the one from the restaurants plus \(2\sigma^2\) (Donald & Lang, 2007):

Code
sig <- seq(0, 2, length.out = 100); sdw <- sqrt(se_cl^2 + 2 * sig^2)
ggplot(data.frame(sig, lo = est - 1.96 * sdw, hi = est + 1.96 * sdw), aes(sig)) +
  geom_ribbon(aes(ymin = lo, ymax = hi), fill = "#2a78d6", alpha = 0.25) +
  geom_hline(yintercept = est, colour = "#2a78d6") +
  geom_hline(yintercept = 0, linetype = "dashed") +
  labs(
    title = "95% interval of the DiD, if states have shocks of their own",
    x = "standard deviation of the shock of a state (FTE per restaurant)",
    y = "DiD"
  ) +
  theme_bw()

State shock – Two states are two observations

Code
sigma_limit <- sqrt(((est / 1.96)^2 - se_cl^2) / 2)
interval1 <- est + c(-1.96, 1.96) * sqrt(se_cl^2 + 2)
cbind(
  value = c(
    sigma_at_which_the_interval_reaches_zero = sigma_limit,
    low_if_sigma_1 = interval1[1],
    high_if_sigma_1 = interval1[2]
  )
)
                                              value
sigma_at_which_the_interval_reaches_zero  0.3650511
low_if_sigma_1                           -1.0202071
high_if_sigma_1                           6.5274187

Shocks with an SD of 0.37 FTE (1.8% of a restaurant’s staff) are enough to take the significance away. And nothing in the data can tell us how large they are, because each state was seen once. With an SD of 1 the interval is [-1.0, 6.5]. A large loss of jobs is still hard to reconcile with the data; a small one is not. This is the general lesson of Bertrand et al. (2004) as well: cluster at the level at which the treatment was given, and have many such clusters.

Were the groups alike?

The restaurants in Pennsylvania were larger at the first interview (23.3 against 20.4). Large ones tend to shrink, and small ones to grow, if only because an interview catches a busy or a quiet week (regression to the mean). One could adjust for the first value:

Code
ancova <- feols(fte2 ~ nj + fte1, both, vcov = "hetero")
rbind(
  `difference in differences` = c(estimate = coef(change_fit)[["nj"]], SE = se(change_fit)[["nj"]]),
  `adjusted for the first value` = c(coef(ancova)[["nj"]], se(ancova)[["nj"]])
)
                             estimate       SE
difference in differences    2.750000 1.337725
adjusted for the first value 1.338523 0.992067
Code
c(
  slope_of_the_first_value = coef(ancova)[["fte1"]],
  correlation_of_the_two_interviews = with(both, cor(fte1, fte2))
)
         slope_of_the_first_value correlation_of_the_two_interviews 
                        0.5214388                         0.5537823 

With the first value as a control, the effect is 1.34 (SE 0.99). The two methods answer with different assumptions: DiD says that the states differ permanently, and that the difference would have stayed the same; the other says that a restaurant with 20 FTE in New Jersey and one with 20 in Pennsylvania would have had the same future. DiD forces the slope of the first value to be 1; the data say 0.52. Neither is right by itself. (The conflict is known as Lord’s paradox.)

What others found

Neumark and Wascher (2000) collected payroll records of restaurants in the same two states and found a loss of jobs in New Jersey. Card and Krueger (2000) answered with official payroll records: employment grew as fast in New Jersey as in Pennsylvania, or slightly faster. How good the interview data are was a part of that debate.


7. When the treatment comes in waves

Laws rarely come in one place and on one day. Some states raise the wage in 1990, some in 1994, some never. For twenty years people ran one regression with unit and time effects and a treatment indicator (TWFE) on such data. If the effect grows with time or differs between places, that is wrong (Goodman-Bacon, 2021): the regression also uses places that were treated early as controls for those treated late. A simulation where we know the truth:

Code
set.seed(231); n_unit <- 300; n_time <- 10
panel <- expand.grid(t = 1:n_time, id = 1:n_unit)
# treated from period 4, from period 8, never
panel$first <- rep(c(4, 8, 0), each = n_unit / 3)[panel$id]
panel$treated <- as.numeric(panel$first > 0 & panel$t >= panel$first)
# grows each year; faster in the early group
panel$effect <- panel$treated * ifelse(panel$first == 4, 1, 0.3) * (panel$t - panel$first + 1)
unit_level <- rnorm(n_unit, 0, 2) + ifelse(rep(c(4, 8, 0), each = n_unit / 3) == 4, 2, 0)
time_level <- cumsum(rnorm(n_time, 0.2, 0.5))
# parallel trends hold exactly
panel$y <- unit_level[panel$id] + time_level[panel$t] + panel$effect + rnorm(nrow(panel))
truth      <- mean(panel$effect[panel$treated == 1])
twfe       <- feols(y ~ treated | id + t, panel, cluster = ~ id)
twfe_no_never <- feols(y ~ treated | id + t, subset(panel, first > 0), cluster = ~ id)
c(
  true_mean_effect = truth,
  TWFE = coef(twfe)[["treated"]],
  TWFE_without_the_never_treated = coef(twfe_no_never)[["treated"]]
)
              true_mean_effect                           TWFE TWFE_without_the_never_treated 
                    2.98000000                     1.51468484                    -0.07322945 

The true mean effect is 2.98. Every single effect is positive, and the trends are exactly parallel. TWFE says 1.51, and without the group that was never treated even -0.07.

The remedy (Callaway & Sant’Anna, 2021) is to go back to the simple idea of step 1. For every group \(g\) and every period \(t\), do one DiD: with the period before the group’s treatment as “before”, and the never-treated as controls. Then average:

\[ATT(g, t) = (\bar y_{g,t} - \bar y_{g,g-1}) - (\bar y_{\text{never},t} - \bar y_{\text{never},g-1})\]

Code
ym <- function(g, t) mean(panel$y[panel$first == g & panel$t == t])
att <- do.call(
  rbind,
  lapply(c(4, 8), function(g) {
    data.frame(
      group = g,
      t = g:n_time,
      by_hand = sapply(g:n_time, function(t) (ym(g, t) - ym(g, g - 1)) - (ym(0, t) - ym(0, g - 1))),
      truth = sapply(g:n_time, function(t) mean(panel$effect[panel$first == g & panel$t == t]))
    )
  })
)
cs <- did::att_gt(
  yname = "y",
  tname = "t",
  idname = "id",
  gname = "first",
  data = panel,
  control_group = "nevertreated",
  bstrap = FALSE,
  cband = FALSE,
  base_period = "universal"
)
att$did_package <- cs$att[match(paste(att$group, att$t), paste(cs$group, cs$t))]
print(round(att, 2), row.names = FALSE)
 group  t by_hand truth did_package
     4  4    1.06   1.0        1.06
     4  5    1.74   2.0        1.74
     4  6    2.87   3.0        2.87
     4  7    3.82   4.0        3.82
     4  8    4.77   5.0        4.77
     4  9    5.80   6.0        5.80
     4 10    6.94   7.0        6.94
     8  8    0.50   0.3        0.50
     8  9    0.57   0.6        0.57
     8 10    1.07   0.9        1.07
Code
overall <- did::aggte(cs, type = "simple", bstrap = FALSE, cband = FALSE)
c(
  mean_by_hand = mean(att$by_hand),
  did_package = overall$overall.att,
  SE = overall$overall.se,
  truth = truth
)
mean_by_hand  did_package           SE        truth 
   2.9151585    2.9151585    0.1449522    2.9800000 
Code
es <- data.frame(group = cs$group, t = cs$t, est = cs$att, se = cs$se)
es$rel <- es$t - es$group
es$group <- paste("treated from period", es$group)
es$se[is.na(es$se)] <- 0
tr <- data.frame(
  group = paste("treated from period", att$group),
  rel = att$t - att$group,
  truth = att$truth
)
ggplot(es, aes(rel, est)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_vline(xintercept = -0.5, colour = "grey60") +
  geom_linerange(aes(ymin = est - 1.96 * se, ymax = est + 1.96 * se), colour = "#2a78d6") +
  geom_point(colour = "#2a78d6", size = 2) +
  geom_point(data = tr, aes(rel, truth), shape = 4, colour = "#eb6834", size = 2.4) +
  facet_wrap(~group) +
  labs(
    title = "Group-time effects, before and after the treatment",
    subtitle = "Crosses: the truth. Left of the line: there should be nothing",
    x = "periods since the treatment began",
    y = "effect"
  ) +
  theme_bw()

Group time chart – 7. When the treatment comes in waves

The group-time effects agree with the truth, and their mean is 2.92. The points to the left of the line are the check that we could not make with two interviews: before the treatment there should be nothing. Of the 8 intervals, 1 misses zero. Here we know that this is chance. With real data one would not, and a test of the trends before the treatment can fail in both directions.


8. Things to keep in mind

  • The assumption is about changes, not levels. The groups may differ, but they must not be on different tracks.
  • Draw the periods before the treatment, as many as there are. Parallel trends before do not prove parallel trends after, but a difference is a warning.
  • The scale (levels, logs, percentages) is a part of the assumption.
  • Cluster at the level at which the treatment was given. With few clusters the usual formula is too optimistic. With two, there is no honest standard error at all.
  • Anticipation: if people react before the law starts, the period before is already treated.
  • Spillovers: if the customers of New Jersey drive to Pennsylvania, the control group is affected as well.
  • Composition: in a repeated cross-section the groups may change who is in them.
  • Control variables must not be changed by the treatment.
  • Staggered treatment: do not use the plain two-way regression. Use did, fixest::sunab(), or one DiD at a time.
  • Relatives: panel data, instrumental variables, regression discontinuity, and interrupted time series when there is no control group.

9. Reporting the results in APA style

A report (APA 7th edition) needs the treatment, the groups and the periods, the four means, the estimate with clustered standard errors and the level of the clusters, the argument for parallel trends with the evidence for it (or its absence), the other comparisons, and the sensitivity. The numbers come from the R objects:

Code
mean_se <- function(v) {
  paste0(f2(mean(v, na.rm = TRUE)), " (", f2(sd(v, na.rm = TRUE) / sqrt(sum(!is.na(v)))), ")")
}
apa_table <- data.frame(
  State = c("New Jersey", "Pennsylvania", "Difference in differences"),
  before = c(mean_se(stores$fte1[stores$nj == 1]), mean_se(stores$fte1[stores$nj == 0]), ""),
  after = c(mean_se(stores$fte2[stores$nj == 1]), mean_se(stores$fte2[stores$nj == 0]), ""),
  change = c(
    f2(diff(m["New Jersey", ])),
    f2(diff(m["Pennsylvania", ])),
    paste0(f2(est), " (", f2(se_cl), ")")
  )
)

Method (data analysis):

The effect of New Jersey’s increase in the minimum wage (from $4.25 to $5.05 on 1 April 1992) on employment in fast-food restaurants was estimated with a difference-in-differences design. 410 restaurants in New Jersey (n = 331) and eastern Pennsylvania (n = 79), where the minimum wage did not change, were interviewed before and after the increase (Card & Krueger, 1993). The outcome was the number of full-time equivalents (full-time employees and managers plus half of the part-time employees); restaurants that had closed permanently were counted as zero. We regressed the outcome on state, period and their product, with standard errors clustered by restaurant. The analysis assumes that employment in New Jersey would have changed as in Pennsylvania without the law; with two interviews this cannot be examined, and we report how large a violation would change the conclusion. Comparisons within New Jersey used the increase that each restaurant needed to reach the new minimum. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026).

Results:

Mean employment rose from 20.44 to 21.03 full-time equivalents in New Jersey and fell from 23.33 to 21.17 in Pennsylvania (Table 1). The difference in differences was 2.75, SE = 1.31, 95% CI [0.19, 5.32], p = .036. Across the restaurants of both states, a wage gap of 10% was associated with a change of 1.64 full-time equivalents (SE = 0.60). On the log scale the difference was 0.08 (p = .111), and adjusted for employment at the first interview it was 1.34 (SE = 0.99). A difference in trends of 0.19 between the states, or random shocks to the states with a standard deviation of 0.37, would suffice to make the result compatible with no effect. The data give no evidence for a loss of jobs, but the evidence for a gain is weak.

Table 1

Mean Employment (Full-Time Equivalents per Restaurant) Before and After the Increase in New Jersey’s Minimum Wage

State Before After Change
New Jersey 20.44 (0.51) 21.03 (0.52) 0.59
Pennsylvania 23.33 (1.35) 21.17 (0.94) -2.17
Difference in differences 2.75 (1.31)

Note. Standard errors in parentheses; for the difference in differences clustered by restaurant. All available interviews.

Points to remember:

  • Show the four means, not only the estimate.
  • Say at which level the errors are clustered, and how many clusters there are.
  • Say what the evidence for parallel trends is. If there is none, say that.
  • Report other comparisons, scales and definitions, also those that disagree.

10. Summary

When A treatment reaches one group and not another, and both are seen before and after
The estimate Change in the treated group minus change in the control group
The assumption Without the treatment both would have changed alike (parallel trends)
How (R) lm(y ~ group * after), or feols(y ~ treated | unit + time, cluster = ~ unit)
Standard errors Clustered at the level of the treatment; few clusters are a problem
Check Periods before the treatment, other control groups, placebo outcomes, other scales, sensitivity
In waves Group-time effects (did::att_gt(), fixest::sunab()), not plain TWFE
Related pages Panel data, instrumental variables, regression discontinuity

References

Bertrand, M., Duflo, E., & Mullainathan, S. (2004). How much should we trust differences-in-differences estimates? The Quarterly Journal of Economics, 119(1), 249–275. https://doi.org/10.1162/003355304772839588

Callaway, B., & Sant’Anna, P. H. C. (2021). Difference-in-differences with multiple time periods. Journal of Econometrics, 225(2), 200–230. https://doi.org/10.1016/j.jeconom.2020.12.001

Card, D., & Krueger, A. B. (1993). Minimum wages and employment: A case study of the fast food industry in New Jersey and Pennsylvania (NBER Working Paper No. 4509). National Bureau of Economic Research. https://doi.org/10.3386/w4509

Card, D., & Krueger, A. B. (2000). Minimum wages and employment: A case study of the fast-food industry in New Jersey and Pennsylvania: Reply. American Economic Review, 90(5), 1397–1420. https://doi.org/10.1257/aer.90.5.1397

Donald, S. G., & Lang, K. (2007). Inference with difference-in-differences and other panel data. Review of Economics and Statistics, 89(2), 221–233. https://doi.org/10.1162/rest.89.2.221

Goodman-Bacon, A. (2021). Difference-in-differences with variation in treatment timing. Journal of Econometrics, 225(2), 254–277. https://doi.org/10.1016/j.jeconom.2021.03.014

Neumark, D., & Wascher, W. (2000). Minimum wages and employment: A case study of the fast-food industry in New Jersey and Pennsylvania: Comment. American Economic Review, 90(5), 1362–1396. https://doi.org/10.1257/aer.90.5.1362

Rambachan, A., & Roth, J. (2023). A more credible approach to parallel trends. Review of Economic Studies, 90(5), 2555–2591. https://doi.org/10.1093/restud/rdad018