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:
y1numpy.ndarray

A 1D array of outcomes from the post-treatment period.

y0numpy.ndarray

A 1D array of outcomes from the pre-treatment period.

dnumpy.ndarray

A 1D array of group indicators (1 if treated in post-treatment, 0 otherwise).

covariatesnumpy.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_weightsnumpy.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).

nbootint, default=999

Number of bootstrap repetitions (not relevant if boot = False).

influence_funcbool, default=False

Whether to return the influence function.

Returns:
TWFEDIDPanelResult

A 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_panel

Outcome regression DiD for panel data.

drdid_imp_panel

Improved doubly robust DiD for panel data.

ipw_did_panel

Inverse 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 ordid function 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