Skip to contents

Estimates 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

set.seed(1)
if (morie_crypto_liboqs_available()) {
  if (requireNamespace("did", quietly = TRUE)) {
    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")
  }
}