Skip to contents

Stage 1: estimate unit and time fixed effects from untreated observations only and residualize the outcome everywhere. Stage 2: regress the residualized outcome on the treated-post indicator. Standard error by cluster (unit) bootstrap of both stages, which accounts for the first-stage estimation error the naive OLS SE misses.

Usage

morie_did_did2s(
  data,
  outcome,
  unit,
  time,
  treatment_time,
  n_bootstrap = 199L,
  seed = 42L,
  alpha = 0.05
)

Arguments

data

Long panel data frame.

outcome, unit, time

Column names.

treatment_time

First treated period per unit (NA = never).

n_bootstrap

Cluster-bootstrap replications. Default 199.

seed

RNG seed.

alpha

CI tail.

Value

List of class "morie_did".

References

Gardner (2022) "Two-stage differences in differences", working paper.

Examples

df <- expand.grid(id = 1:40, t = 1:8)
df$g <- ifelse(df$id <= 20, 5L, NA)
df$y <- rnorm(nrow(df)) + ifelse(!is.na(df$g) & df$t >= df$g, 2, 0)
morie_did_did2s(df, "y", "id", "t", "g", n_bootstrap = 29L)
#> Difference-in-differences -- Gardner (2022) two-stage DiD (cluster bootstrap SE) 
#>   ATT: 1.7905  (SE 0.2747)  95% CI [1.2522, 2.3289]  p = 7.09e-11
#>   Units: 40  Periods: 8