
Goodman-Bacon decomposition of the TWFE DiD estimator
Source:R/did.R
morie_did_bacon_decomposition.RdNative Goodman-Bacon (2021) decomposition: the two-way
fixed-effects DiD estimate is decomposed into a weighted average of
all 2x2 timing comparisons, with each pair's weight derived from
the Frisch-Waugh-Lovell identity (subsample size squared times the
variance of the demeaned treatment). Reproduces
bacondecomp::bacon exactly (see tests/cross/).
References
Goodman-Bacon, A. (2021). Difference-in-differences with variation in treatment timing. Journal of Econometrics, 225(2), 254–277.
Examples
set.seed(1)
df <- expand.grid(unit = 1:30, time = 1:6)
df$treat_time <- ifelse(df$unit <= 15, 4, Inf)
df$d <- as.integer(df$time >= df$treat_time)
df$y <- 0.1 * df$time + 0.7 * df$d + rnorm(nrow(df), sd = 0.4)
out <- morie_did_bacon_decomposition(df, "y", "d", "unit", "time")
out$overall_estimate
#> [1] 0.6266604