run_es()
is a user-friendly event study wrapper for panel data, supporting both classic (universal timing) and staggered (unit-varying timing) settings. It generates lead/lag dummy variables around treatment, builds the regression formula, and returns tidy results with confidence intervals for arbitrary levels.
run_es(
data,
outcome,
treatment,
time,
timing,
fe,
lead_range = NULL,
lag_range = NULL,
covariates = NULL,
cluster = NULL,
weights = NULL,
baseline = -1,
interval = 1,
time_transform = FALSE,
unit = NULL,
staggered = FALSE,
conf.level = 0.95
)
A data.frame with class "es_result"
, containing:
Dummy variable name (leadX
, lagY
)
Coefficient estimates, standard errors, test statistics, and p-values
Confidence intervals at each requested level
Period relative to treatment (0 = event)
Logical, is this the baseline period (estimate always 0)
Attributes: lead_range
, lag_range
, baseline
, interval
, call
, model_formula
, conf.level
.
A data.frame with panel data. Must contain all required variables.
Outcome variable (unquoted variable name or expression, e.g. log(y)
).
Treatment indicator (unquoted; 0/1 or logical).
Time variable (unquoted; numeric or Date).
Treatment timing: a numeric or Date for universal timing, or a variable (unquoted) for staggered.
One-sided formula for fixed effects (e.g. ~ id + year
).
Number of pre-treatment periods to include (default: detected from data).
Number of post-treatment periods to include (default: detected from data).
One-sided formula of additional controls (optional).
Cluster variable(s), as a one-sided formula or character vector (optional).
Observation weights (formula, character, or unquoted variable).
Baseline period for normalization (default: -1, i.e., one period before treatment).
Numeric; interval of the time variable (default: 1).
Logical; if TRUE
, converts time variable to consecutive integer within units (requires unit
).
Panel unit variable (required if time_transform = TRUE
).
Logical; if TRUE
, treats timing as variable (default: FALSE
).
Numeric vector of confidence levels (e.g. c(0.90, 0.95, 0.99)
; default: 0.95
).
One-step event study: specify outcome, treatment, time, timing, and fixed effects directly.
Supports both universal and staggered treatment timing.
Flexible covariate, clustering, and weighting options.
Customizable lead/lag window and baseline normalization.
Returns a tidy data.frame
(class "es_result"
) with estimates and confidence intervals.
Yosuke Abe
Runs an event study regression on panel data, automatically generating lead/lag dummies around a treatment event.
The function does not require explicit formula specification; dummy variables and model formula are constructed internally. Baseline normalization (reference category) can be customized. Untreated units or units never treated are supported. Missing values in key variables result in an error.
plot_es
if (FALSE) {
# Simulated example
result <- run_es(
data = panel_data,
outcome = y,
treatment = treated_1998,
time = year,
timing = 1998,
fe = ~ firm_id + year,
cluster = ~ state_id,
lead_range = 3,
lag_range = 3,
conf.level = c(0.90, 0.95, 0.99)
)
plot_es(result)
}
Run the code above in your browser using DataLab