This function allows for the estimation of treatment effects using different estimators. Currently, it supports “twfe” for the two-way fixed effects estimator and “did2s” for Gardner’s two-step DID2S estimator. Other estimators are in development.
Parameters
Name
Type
Description
Default
data
DataFrame
The DataFrame containing all variables.
required
yname
str
The name of the dependent variable.
required
idname
str
The name of the id variable.
required
tname
str
Variable name for calendar period.
required
gname
str
Unit-specific time of initial treatment.
required
xfml
str
The formula for the covariates.
None
estimator
str
The estimator to use. Options are “did2s” and “twfe”.
'twfe'
att
bool
If True, estimates the average treatment effect on the treated (ATT). If False, estimates the canonical event study design with all leads and lags. Default is True.
True
cluster
Optional[str]
The name of the cluster variable.
'idname'
Returns
Name
Type
Description
object
A fitted model object of class [Feols(/reference/Feols.qmd).
Examples
import pandas as pdimport pyfixest as pfurl ="https://raw.githubusercontent.com/py-econometrics/pyfixest/master/pyfixest/did/data/df_het.csv"df_het = pd.read_csv(url)fit_twfe = pf.event_study( df_het, yname="dep_var", idname="unit", tname="year", gname="g", estimator="twfe", att=True,)fit_twfe.tidy()