run_es {fixes} | R Documentation |
Event Study Estimation for Panel Data
Description
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.
Usage
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
)
Arguments
data |
A data.frame with panel data. Must contain all required variables. |
outcome |
Outcome variable (unquoted variable name or expression, e.g. |
treatment |
Treatment indicator (unquoted; 0/1 or logical). |
time |
Time variable (unquoted; numeric or Date). |
timing |
Treatment timing: a numeric or Date for universal timing, or a variable (unquoted) for staggered. |
fe |
One-sided formula for fixed effects (e.g. |
lead_range |
Number of pre-treatment periods to include (default: detected from data). |
lag_range |
Number of post-treatment periods to include (default: detected from data). |
covariates |
One-sided formula of additional controls (optional). |
cluster |
Cluster variable(s), as a one-sided formula or character vector (optional). |
weights |
Observation weights (formula, character, or unquoted variable). |
baseline |
Baseline period for normalization (default: -1, i.e., one period before treatment). |
interval |
Numeric; interval of the time variable (default: 1). |
time_transform |
Logical; if |
unit |
Panel unit variable (required if |
staggered |
Logical; if |
conf.level |
Numeric vector of confidence levels (e.g. |
Details
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.
Value
A data.frame with class "es_result"
, containing:
- term
Dummy variable name (
leadX
,lagY
)- estimate, std.error, statistic, p.value
Coefficient estimates, standard errors, test statistics, and p-values
- conf_low_XX, conf_high_XX
Confidence intervals at each requested level
- relative_time
Period relative to treatment (0 = event)
- is_baseline
Logical, is this the baseline period (estimate always 0)
Attributes: lead_range
, lag_range
, baseline
, interval
, call
, model_formula
, conf.level
.
Key Features
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.
Author(s)
Yosuke Abe
See Also
Examples
## Not run:
# 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)
## End(Not run)