
Difference-in-differences with automatic staggered-design handling
Source:R/quasiex_native.R
morie_did.RdEstimates the ATT by two-way fixed effects when treatment timing is uniform, and switches automatically to the Callaway & Sant'Anna (2021) group-time estimator when adoption is staggered – warning that a naive TWFE specification would be contaminated by forbidden already-treated comparisons (Goodman-Bacon 2021).
Usage
morie_did(
data,
outcome,
unit,
time,
treatment_time,
covariates = NULL,
n_bootstrap = 200L,
seed = 42L,
alpha = 0.05
)Arguments
- data
Data frame (long panel).
- outcome, unit, time
Column names.
- treatment_time
Column giving each unit's first treated period (NA/Inf = never treated).
- covariates
Optional covariate names (staggered path).
- n_bootstrap
Multiplier-bootstrap reps for the staggered SEs.
- seed
RNG seed.
- alpha
CI level tail. Default 0.05.
Value
Object of class "morie_did": estimate, std.error,
conf.int, p.value, att_gt (staggered only), method, n_units,
n_periods, call.
References
Callaway & Sant'Anna (2021) J. Econometrics 225(2); Goodman-Bacon (2021) J. Econometrics 225(2).
Examples
df <- expand.grid(id = 1:30, t = 1:6)
df$g <- ifelse(df$id <= 15, 4L, NA)
df$y <- rnorm(nrow(df)) + ifelse(!is.na(df$g) & df$t >= df$g, 2, 0)
morie_did(df, "y", "id", "t", "g")
#> Difference-in-differences -- TWFE DiD (uniform timing), cluster-robust on unit
#> ATT: 1.7422 (SE 0.3169) 95% CI [1.1211, 2.3633] p = 3.85e-08
#> Units: 30 Periods: 6