Type: Package
Title: Tools for Creating and Visualizing Fixed-Effects Event Study Models
Version: 0.5.0
Description: Provides functions for creating, analyzing, and visualizing event study models using fixed-effects regression. Supports staggered adoption, multiple confidence intervals, flexible clustering, and panel/time transformations in a simple workflow.
Depends: R (≥ 4.1.0)
Imports: dplyr, ggplot2, fixest, broom, tibble, rlang
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Suggests: knitr, rmarkdown, haven, testthat
VignetteBuilder: knitr
URL: https://github.com/yo5uke/fixes
BugReports: https://github.com/yo5uke/fixes/issues
NeedsCompilation: no
Packaged: 2025-07-07 10:12:27 UTC; yo5uk
Author: Yosuke Abe [aut, cre]
Maintainer: Yosuke Abe <yosuke.abe0507@gmail.com>
Repository: CRAN
Date/Publication: 2025-07-07 10:30:06 UTC

Plot Event Study Results

Description

plot_es() produces standard event study plots, showing estimated effects and confidence intervals across event time. Supports both ribbon and errorbar styles, multiple confidence levels, and several ggplot2 themes.

Usage

plot_es(
  data,
  ci_level = 0.95,
  type = "ribbon",
  vline_val = 0,
  vline_color = "#000",
  hline_val = 0,
  hline_color = "#000",
  linewidth = 1,
  pointsize = 2,
  alpha = 0.2,
  barwidth = 0.2,
  color = "#B25D91FF",
  fill = "#B25D91FF",
  theme_style = "bw"
)

Arguments

data

Data frame returned by run_es().

ci_level

Confidence level for intervals (numeric, e.g. 0.95). Must match columns like 'conf_low_95'.

type

Confidence interval style: "ribbon" (default) or "errorbar".

vline_val

X value for vertical reference line (default: 0).

vline_color

Color for vertical line.

hline_val

Y value for horizontal reference line (default: 0).

hline_color

Color for horizontal line.

linewidth

Width of estimate line or error bars.

pointsize

Point size for estimates.

alpha

Transparency for ribbon (default: 0.2).

barwidth

Width of error bars (if type = "errorbar").

color

Color for lines and points.

fill

Fill color for ribbon.

theme_style

ggplot2 theme: "bw" (default), "minimal", or "classic".

Details

Visualizes event study estimates and confidence intervals produced by run_es().

Value

A ggplot2 object.

Author(s)

Yosuke Abe

See Also

run_es

Examples

## Not run: 
result <- run_es(...)
plot_es(result, ci_level = 0.95, type = "ribbon")

## End(Not run)


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. 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).

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

Author(s)

Yosuke Abe

See Also

plot_es

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)