EventStudy#

class causalpy.experiments.event_study.EventStudy[source]#

Estimate dynamic treatment effects when every treated unit is treated together.

This is the classical event-study regression: unit and time fixed effects, plus a dummy for each event time other than a reference period. Event time is calendar time minus the unit’s treatment time. Coefficients are treatment effects relative to the reference event time, not relative to zero calendar time.

The design requires one common treatment time. Staggered adoption is rejected; use StaggeredDifferenceInDifferences for that design. This estimator does not implement the Callaway and Sant’Anna or Sun and Abraham heterogeneous-timing corrections.

Configuration validates the panel and builds the design. Sampling happens in fit(). Draw-derived coefficients live on EventStudyResult, not on the experiment.

Parameters:
  • data (DataFrameLike) – Panel with one row per unit-time observation.

  • formula (str) – Patsy formula for the outcome, fixed effects, and covariates, such as "y ~ 1 + C(unit) + C(time)". Event-time dummies are added by the experiment; do not put them in the formula.

  • unit_col (str) – Column identifying units.

  • time_col (str) – Column identifying time periods. Must be numeric enough that differences are event times.

  • treat_time_col (str) – Column of treatment times. NaN or inf marks a never-treated unit.

  • event_window (tuple[int, int]) – Inclusive (minimum, maximum) event times to estimate. The minimum must be strictly less than the maximum.

  • reference_event_time (int) – Omitted event time, normalized to zero. Must lie inside event_window. -1 is the last pre-treatment period.

  • model (PyMCModel | RegressorMixin | None) – Statistical model. None uses LinearRegression.

Examples

>>> import causalpy as cp
>>> from sklearn.linear_model import LinearRegression
>>> from causalpy.data.simulate_data import generate_event_study_data
>>> df = generate_event_study_data(n_units=8, n_time=8, treatment_time=4, seed=1)
>>> experiment = cp.EventStudy(
...     df,
...     formula="y ~ 1 + C(unit) + C(time)",
...     unit_col="unit",
...     time_col="time",
...     treat_time_col="treat_time",
...     event_window=(-2, 2),
...     model=cp.create_causalpy_compatible_class(LinearRegression()),
... )
>>> experiment.is_fitted
False

Methods

EventStudy.build()

Construct the model graph without sampling anything.

EventStudy.effect_summary(*[, group, ...])

Summarize dynamic effects relative to the reference event time.

EventStudy.fit(**kwargs)

Run the posterior phase and populate result.

EventStudy.generate_report(*[, ...])

Generate a self-contained HTML report for this experiment.

EventStudy.get_event_time_summary(*[, ...])

Return event-time means and, when draws exist, interval bounds.

EventStudy.get_plot_data(*[, group, hdi_prob])

Return the event-time table used by plot().

EventStudy.input_validation()

Validate the formula, panel keys, window, and common treatment time.

EventStudy.plot(*[, group, hdi_prob, ...])

Plot event-time coefficients.

EventStudy.print_coefficients([round_to])

Ask the model to print its posterior coefficients.

EventStudy.sample_prior_predictive(**kwargs)

Run the optional prior phase and populate prior_result.

EventStudy.set_maketables_options(*[, hdi_prob])

Set optional maketables rendering options for this experiment.

EventStudy.summary([round_to])

Print the design and the posterior event-time coefficients.

Attributes

has_prior_predictive

Whether the prior phase has run (draws, and bundle where kept).

idata

Return fitted DataTree when the model backend supports it.

is_built

Whether the model graph / fit design exists (no draws implied).

is_configured

design matrices are ready.

is_fitted

Whether posterior draws and the posterior result bundle exist.

model

The underlying model instance.

prior_result

Prior-group result bundle; raises before prior sampling.

result

Posterior-group result bundle; raises before fit().

supports_bayes

supports_ols

supports_pymc_forecast

labels

data

__init__(data, formula, unit_col, time_col, treat_time_col, event_window=(-5, 5), reference_event_time=-1, model=None)[source]#
Parameters:
Return type:

None

classmethod __new__(*args, **kwargs)#