import pandas as pd
import pyfixest as pf
= "https://raw.githubusercontent.com/py-econometrics/pyfixest/master/pyfixest/did/data/df_het.csv"
url = pd.read_csv(url)
df_het
= pf.lpdid(
fit
df_het,="dep_var",
yname="unit",
idname="year",
tname="g",
gname={"CRV1": "state"},
vcov=-20,
pre_window=20,
post_window=False
att
)
fit.tidy().head()= [1200, 400], coord_flip=False).show() fit.iplot(figsize
did.estimation.lpdid
did.estimation.lpdid(
data,
yname,
idname,
tname,
gname,=None,
vcov=None,
pre_window=None,
post_window=0,
never_treated=True,
att=None,
xfml )
Local projections approach to estimation.
Estimate a Difference-in-Differences / Event Study Model via the Local Projections Approach.
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 |
vcov | (str, dict) | The type of inference to employ. Defaults to {“CRV1”: idname}. Options include “iid”, “hetero”, or a dictionary like {“CRV1”: idname}. | None |
pre_window | int | The number of periods before the treatment to include in the estimation. Default is the minimum relative year in the data. | None |
post_window | int | The number of periods after the treatment to include in the estimation. Default is the maximum relative year in the data. | None |
never_treated | int | Value in gname indicating units never treated. Default is 0. | 0 |
att | bool | If True, estimates the pooled average treatment effect on the treated (ATT). Default is False. | True |
xfml | str | Formula for the covariates. Not yet supported. | None |
Returns
Name | Type | Description |
---|---|---|
DataFrame | A DataFrame with the estimated coefficients. |
Examples
To get the ATT, set att=True
:
= pf.lpdid(
fit
df_het,="dep_var",
yname="unit",
idname="year",
tname="g",
gname={"CRV1": "state"},
vcov=-20,
pre_window=20,
post_window=True
att
) fit.tidy()
Estimate | Std. Error | t value | Pr(>|t|) | 2.5% | 97.5% | N | |
---|---|---|---|---|---|---|---|
treat_diff | 2.506746 | 0.071357 | 35.129648 | 0.0 | 2.362413 | 2.65108 | 5716.0 |