% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/run_es.R
\name{run_es}
\alias{run_es}
\title{Event Study Estimation for Panel Data}
\usage{
run_es(
  data,
  outcome,
  treatment = NULL,
  time,
  timing,
  fe = NULL,
  lead_range = NULL,
  lag_range = NULL,
  covariates = NULL,
  cluster = NULL,
  weights = NULL,
  baseline = -1L,
  interval = 1,
  time_transform = FALSE,
  unit = NULL,
  staggered = FALSE,
  method = c("classic", "sunab"),
  estimator = c("twfe", "cs", "sa", "bjs"),
  control_group = c("nevertreated", "notyettreated"),
  anticipation = 0L,
  conf.level = 0.95,
  vcov = "HC1",
  vcov_args = list(),
  bootstrap = FALSE,
  B = 999L,
  alpha = 0.05,
  boot_seed = NULL
)
}
\arguments{
\item{data}{A data.frame containing panel data.}

\item{outcome}{Unquoted outcome (name or expression, e.g., \code{log(y)}).}

\item{treatment}{Unquoted treatment indicator (0/1 or logical). Used only when \code{method = "classic"}.}

\item{time}{Unquoted time variable (numeric or Date).}

\item{timing}{For \code{classic}: a numeric/Date (universal) or a variable (unquoted) if \code{staggered = TRUE}. For \code{sunab}: an unquoted variable with adoption time. For \code{estimator = "cs"}: unquoted column giving each unit's first treatment period (\code{NA} = never treated).}

\item{fe}{One-sided fixed-effects formula, e.g., \code{~ id + year}. Can be \code{NULL} for no fixed effects. Ignored when \code{estimator = "cs"}.}

\item{lead_range, lag_range}{Integers for pre/post windows. If \code{NULL}, determined automatically.}

\item{covariates}{One-sided formula of additional controls, e.g., \code{~ x1 + log(x2)}.}

\item{cluster}{Cluster specification (one-sided formula like \code{~ id + year}, a single character column name, or a vector of length \code{nrow(data)}).}

\item{weights}{Observation weights (a name/one-sided formula or a numeric vector of length \code{nrow(data)}).}

\item{baseline}{Integer baseline period (default \code{-1}); reference period excluded from results for both \code{"classic"} and \code{"sunab"} methods.}

\item{interval}{Numeric spacing of the time variable (default \code{1}; ignored internally for Dates).}

\item{time_transform}{Logical; if \code{TRUE}, creates consecutive integer time within unit.}

\item{unit}{Unit identifier variable (required when \code{estimator = "cs"} or \code{time_transform = TRUE}); also used for metadata when supplied.}

\item{staggered}{Logical; if \code{TRUE}, \code{timing} is a variable (classic) or is used by \code{sunab}.}

\item{method}{Either \code{"classic"} or \code{"sunab"} (default: \code{"classic"}).}

\item{estimator}{Estimation strategy: \code{"twfe"} (default, existing fixest-based paths),
\code{"cs"} for the Callaway-Sant'Anna (2021) group-time ATT estimator, or
\code{"sa"} for the Sun-Abraham (2021) interaction-weighted estimator.}

\item{control_group}{For \code{estimator = "cs"}: comparison group, either
\code{"nevertreated"} (default) or \code{"notyettreated"}.}

\item{anticipation}{For \code{estimator = "cs"}: number of anticipation periods
before treatment (non-negative integer, default \code{0L}).}

\item{conf.level}{Numeric vector of confidence levels (default \code{0.95}).}

\item{vcov}{VCOV type passed to \code{fixest::vcov()} or used via \code{broom::tidy(vcov = ...)}. Default \code{"HC1"}.}

\item{vcov_args}{List of additional arguments forwarded to \code{fixest::vcov()}.}

\item{bootstrap}{Logical; if \code{TRUE} and \code{estimator = "cs"}, compute
simultaneous confidence bands via the multiplier bootstrap (Algorithm 1,
Callaway and Sant'Anna 2021).  Adds \code{conf_low_sim} and
\code{conf_high_sim} columns to the result and stores the full (g,t)-level
bootstrap object as \code{attr(result, "bootstrap")}.  Default \code{FALSE}.}

\item{B}{Integer number of bootstrap draws (default \code{999}).  Used only
when \code{bootstrap = TRUE} and \code{estimator = "cs"}.}

\item{alpha}{Significance level for the simultaneous band (default \code{0.05}).
Note: this is independent of \code{conf.level}, which governs the pointwise
delta-method CIs.}

\item{boot_seed}{Integer seed for the bootstrap RNG; \code{NULL} (default)
does not set a seed.  Pass an integer for reproducible results.}
}
\value{
A \code{data.frame} of class \code{"es_result"} with columns:
\itemize{
  \item \code{term}, \code{estimate}, \code{std.error}, \code{statistic}, \code{p.value}
  \item \code{conf_low_XX}, \code{conf_high_XX} (for each requested \code{conf.level})
  \item \code{relative_time} (integer; 0 = event), \code{is_baseline} (logical; marks the reference period)
}
Attributes include: \code{lead_range}, \code{lag_range}, \code{baseline}, \code{interval}, \code{call}, \code{model_formula}, \code{conf.level},
\code{N}, \code{N_units}, \code{N_treated}, \code{N_nevertreated}, \code{fe}, \code{vcov_type}, \code{cluster_vars}, \code{staggered}, \code{sunab_used}.
}
\description{
Runs an event study regression on panel data, supporting both classic (universal timing) and staggered (unit-varying timing via \code{sunab}).
The function builds the design (lead/lag factor or \code{sunab}), estimates with \pkg{fixest}, and returns a tidy table with metadata.
}
\section{Key Features}{

\itemize{
  \item One-step event study: specify outcome, treatment, time, timing, fixed effects, and (optionally) covariates.
  \item Switch between Classic (factor expansion) and Staggered-SAFE (\code{method = "sunab"}).
  \item Flexible clustering, weights, and VCOV choices (e.g., \code{vcov = "HC1" | "HC3" | "CR2" | "iid" ...}).
  \item Automatic lead/lag window detection and customizable baseline period.
  \item Returns an \code{"es_result"} object compatible with \code{print()} and \code{autoplot()}.
}
}

