generate_event_study_data#
- causalpy.data.simulate_data.generate_event_study_data(n_units=20, n_time=20, treatment_time=10, treated_fraction=0.5, event_window=(-5, 5), treatment_effects=None, unit_fe_sigma=1.0, time_fe_sigma=0.5, noise_sigma=0.2, predictor_effects=None, ar_phi=0.9, ar_scale=1.0, seed=None)[source]#
Generate a balanced panel for a simultaneous-adoption event study.
A fraction of units share one treatment time. Outcomes are unit and time fixed effects plus optional AR(1) predictors and an event-time treatment effect. Never-treated units have
NaNintreat_time.- Parameters:
n_units (
int) – Number of units.n_time (
int) – Number of time periods.treatment_time (
int) – Common treatment time for treated units.treated_fraction (
float) – Fraction of units treated.event_window (
tuple[int,int]) – Event times for which default treatment effects are defined.treatment_effects (
dict[int,float] |None) – Map from event time to effect. The default is 0 before treatment and0.5 + 0.1 * kat and after treatment.unit_fe_sigma (
float) – Standard deviations of the unit effect, time effect, and noise.time_fe_sigma (
float) – Standard deviations of the unit effect, time effect, and noise.noise_sigma (
float) – Standard deviations of the unit effect, time effect, and noise.predictor_effects (
dict[str,float] |None) – Map from predictor name to its coefficient. Each predictor is one AR(1) series shared by all units.ar_phi (
float) – AR(1) persistence and innovation scale for predictors.ar_scale (
float) – AR(1) persistence and innovation scale for predictors.seed (
int|None) – Seed for the global NumPy random stream.
- Returns:
Columns
unit,time,y,treat_time,treated, plus one column per predictor.- Return type:
pd.DataFrame
Examples
>>> df = generate_event_study_data( ... n_units=20, n_time=20, treatment_time=10, seed=42 ... ) >>> df.shape (400, 5) >>> df.columns.tolist() ['unit', 'time', 'y', 'treat_time', 'treated']