Learn R Programming

fixes (version 0.5.0)

run_es: 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
)

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.

Arguments

data

A data.frame with panel data. Must contain all required variables.

outcome

Outcome variable (unquoted variable name or expression, e.g. log(y)).

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. ~ id + year).

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 TRUE, converts time variable to consecutive integer within units (requires unit).

unit

Panel unit variable (required if time_transform = TRUE).

staggered

Logical; if TRUE, treats timing as variable (default: FALSE).

conf.level

Numeric vector of confidence levels (e.g. c(0.90, 0.95, 0.99); default: 0.95).

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

Yosuke Abe

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.

See Also

plot_es

Examples

Run this code
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