moderndid.twfe_did_panel#
- moderndid.twfe_did_panel(y1, y0, d, covariates=None, i_weights=None, boot=False, boot_type='weighted', nboot=999, influence_func=False)[source]#
Compute linear two-way fixed effects DiD estimator for the ATT with panel data.
Implements the linear two-way fixed effects (TWFE) estimator for the ATT with panel data, as illustrated in [1]. The estimator is based on the regression model from equation (2.5) of [1] as
\[Y_{it} = \alpha_1 + \alpha_2 T_i + \alpha_3 D_i + \tau^{fe}(T_i \cdot D_i) + \theta' X_i + \varepsilon_{it}.\]- Parameters:
- y1
numpy.ndarray A 1D array of outcomes from the post-treatment period.
- y0
numpy.ndarray A 1D array of outcomes from the pre-treatment period.
- d
numpy.ndarray A 1D array of group indicators (1 if treated in post-treatment, 0 otherwise).
- covariates
numpy.ndarray, optional A 2D array of covariates to be used in the regression estimation. If None, the estimator uses ordid function. The design matrix will always include an intercept.
- i_weights
numpy.ndarray, optional A 1D array of weights. If None, then every observation has equal weight. Weights are normalized to have mean 1.
- bootbool, default=False
Whether to compute bootstrap standard errors.
- boot_type{“weighted”, “multiplier”}, default=”weighted”
Type of bootstrap to be performed (not relevant if boot = False).
- nboot
int, default=999 Number of bootstrap repetitions (not relevant if boot = False).
- influence_funcbool, default=False
Whether to return the influence function.
- y1
- Returns:
TWFEDIDPanelResultA NamedTuple containing the TWFE DiD point estimate, standard error, confidence interval, bootstrap draws, and influence function.
Warning
This estimator generally does not recover the ATT. We encourage users to adopt alternative specifications.
See also
reg_did_panelOutcome regression DiD for panel data.
drdid_imp_panelImproved doubly robust DiD for panel data.
ipw_did_panelInverse propensity weighted DiD for panel data.
Notes
The TWFE estimator is implemented by stacking the panel data and running a regression with treatment-period interaction. When no covariates are provided, this function calls the
ordidfunction directly.References
[1] (1,2)Sant’Anna, P. H. C. and Zhao, J. (2020), “Doubly Robust Difference-in-Differences Estimators.” Journal of Econometrics, Vol. 219 (1), pp. 101-122. https://doi.org/10.1016/j.jeconom.2020.06.003