Learn R Programming

fect (version 2.0.5)

did_wrapper: A Multi-Method Difference-in-Differences Estimator

Description

Implements multiple difference-in-differences (DiD) estimators under a unified interface, supporting overall ATT and event-study estimates across staggered adoption settings.

Usage

did_wrapper(
  data,
  Y,
  D,
  X = NULL,
  index,
  method = c("twfe", "st", "iw", "cs_never", "cs_notyet", "didm"),
  se = c("default", "boot", "bootstrap", "jackknife"),
  nboots = 200,
  parallel = TRUE,
  core = NULL,
  time_to_treat_var = "Time_to_Treatment",
  treat_indicator = "treat",
  csdid.base_period = "universal",
  didm.effects = NA,
  didm.placebo = NA
)

Value

A list of class "did_wrapper":

est.avg

Data frame with overall ATT, standard error, confidence interval, and p-value.

est.att

Event-study ATT estimates by relative period, including standard errors and confidence intervals.

Arguments

data

Input data frame.

Y

Outcome variable name (string).

D

Treatment indicator variable name (string).

X

Optional covariate vector for adjustment.

index

Character vector of unit and time variable names, e.g., c("id", "time").

method

DiD method: "twfe", "st", "iw", "cs_never", "cs_notyet", or "didm".

se

Standard error method: "default", "boot", "bootstrap", or "jackknife".

nboots

Number of bootstrap replications (if applicable).

parallel

Logical; use parallel computation for bootstrapping.

core

Number of CPU cores to use if parallel = TRUE.

time_to_treat_var

Name of time-to-treatment variable; used internally.

treat_indicator

Name of treatment cohort indicator variable; used internally.

csdid.base_period

Baseline period choice for Callaway–Sant'Anna estimators.

didm.effects

Effects vector for didm; required if method = "didm".

didm.placebo

Placebo vector for didm; required if method = "didm".

Author

Rivka Lipkovitz

Details

This function:

  1. Drops always-treated units.

  2. Constructs event time and cohort variables.

  3. Computes ATT using the specified DiD method.

  4. Constructs event-study ATT curves.

  5. Optionally estimates bootstrap or jackknife standard errors.

Supported methods include TWFE, stacked DiD, interaction-weighted DiD, Callaway–Sant'Anna estimators, placebo DiD, and DIDmultiplegt.

Examples

Run this code
if (FALSE) {
result_twfe <- did_wrapper(
  data   = df,
  Y      = "outcome",
  D      = "treat",
  index  = c("id", "time"),
  method = "twfe"
)
result_twfe$est.avg
result_twfe$est.att
}

Run the code above in your browser using DataLab