analyze_event_study

source

analyze_event_study(
    df,
    *,
    outcome,
    unit=None,
    time=None,
    cohort,
    estimator='did2s',
    cluster=None,
    pre_window=None,
    post_window=None,
    never_treated_value=0,
    title=None,
)

Estimate and plot an event study for staggered treatment adoption.

Parameters

Name Type Description Default
df pd.DataFrame Long panel data frame. required
outcome str Outcome variable name. required
unit str | None Unit (cross-section) identifier. Defaults to the declared panel entity. None
time str | None Time identifier. Defaults to the declared panel time. None
cohort str First-treated period for each unit; never_treated_value marks never-treated units. required
estimator Literal['did2s', 'twfe', 'saturated', 'lpdid'] "did2s" (Gardner two-stage, the default and robust to heterogeneity), "twfe" (classic two-way fixed effects — shown for comparison, biased under heterogeneous effects), "saturated" (Sun-Abraham, one curve per cohort) or "lpdid" (local-projections DiD). 'did2s'
cluster str | None Cluster variable for standard errors (defaults to unit). None
pre_window int | None Event-time window for "lpdid" (ignored by the other estimators). None
post_window int | None Event-time window for "lpdid" (ignored by the other estimators). None
never_treated_value int The value of cohort that marks never-treated units (default 0). 0
title str | None Optional figure title. None

Returns

Name Type Description
EventStudyResult df (event-time path), fig (Plotly), model (fitted pyfixest object) and estimator.

Examples

import expdpy as ex
from expdpy.data import load_staggered_did, load_staggered_did_data_def

df = ex.set_labels(
    load_staggered_did(), load_staggered_did_data_def(), set_panel=True
)
# Panel is declared, so unit=/time= are resolved automatically.
ex.analyze_event_study(df, outcome="outcome", cohort="cohort").fig