moderndid.ddd_panel#

moderndid.ddd_panel(y1, y0, subgroup, covariates, i_weights=None, est_method='dr', boot=False, boot_type='multiplier', biters=1000, influence_func=False, alpha=0.05, random_state=None)[source]#

Compute the 2-period doubly robust DDD estimator for the ATT with panel data.

Implements the triple difference-in-differences estimator from [1]. The DDD design exploits three dimensions of variation: treatment status \(S\) (treated vs untreated groups), eligibility \(Q\) (eligible vs ineligible for treatment), and time (pre vs post-treatment periods). This allows for weaker identification assumptions than standard DiD by differencing out both treatment-specific and eligibility-specific heterogeneous trends.

The target parameter is the Average Treatment Effect on the Treated (ATT)

\[ATT(2, 2) = \mathbb{E}[Y_2(2) - Y_2(\infty) \mid S=2, Q=1],\]

where \(S=2\) denotes units in the treatment-enabling group and \(Q=1\) denotes eligibility for treatment.

The doubly robust DDD estimand (Equation 3.5 from [1]) combines three DiD comparisons

\[\begin{split}\widehat{ATT}_{\mathrm{dr}}(2,2) &= \mathbb{E}_n\left[ \left(\widehat{w}_{\mathrm{trt}}^{S=2,Q=1}(S,Q) - \widehat{w}_{\mathrm{comp}}^{S=2,Q=0}(S,Q,X)\right) \left(Y_2 - Y_1 - \widehat{m}_{Y_2-Y_1}^{S=2,Q=0}(X)\right)\right] \\ &+ \mathbb{E}_n\left[ \left(\widehat{w}_{\mathrm{trt}}^{S=2,Q=1}(S,Q) - \widehat{w}_{\mathrm{comp}}^{S=\infty,Q=1}(S,Q,X)\right) \left(Y_2 - Y_1 - \widehat{m}_{Y_2-Y_1}^{S=\infty,Q=1}(X)\right)\right] \\ &- \mathbb{E}_n\left[ \left(\widehat{w}_{\mathrm{trt}}^{S=2,Q=1}(S,Q) - \widehat{w}_{\mathrm{comp}}^{S=\infty,Q=0}(S,Q,X)\right) \left(Y_2 - Y_1 - \widehat{m}_{Y_2-Y_1}^{S=\infty,Q=0}(X)\right)\right],\end{split}\]

where the estimated weights are

\[\widehat{w}_{\mathrm{trt}}^{S=2,Q=1}(S,Q) \equiv \frac{\mathbf{1}\{S=2, Q=1\}}{\mathbb{E}_n[\mathbf{1}\{S=2, Q=1\}]}, \quad \widehat{w}_{\mathrm{comp}}^{S=g,Q=q}(S,Q,X) \equiv \frac{\frac{\mathbf{1}\{S=g, Q=q\} \cdot \widehat{p}^{S=2,Q=1}(X)} {\widehat{p}^{S=g,Q=q}(X)}} {\mathbb{E}_n\left[\frac{\mathbf{1}\{S=g, Q=q\} \cdot \widehat{p}^{S=2,Q=1}(X)} {\widehat{p}^{S=g,Q=q}(X)}\right]}.\]
Parameters:
y1numpy.ndarray

A 1D array of outcomes from the post-treatment period \(Y_t\).

y0numpy.ndarray

A 1D array of outcomes from the pre-treatment period \(Y_{g-1}\).

subgroupnumpy.ndarray

A 1D array of subgroup indicators (1, 2, 3, or 4) for each unit, corresponding to the four cells of the \(S \times Q\) partition:

  • 4: \(S=g, Q=1\) (Treated AND Eligible - target group)

  • 3: \(S=g, Q=0\) (Treated BUT Ineligible)

  • 2: \(S=g_c, Q=1\) (Eligible BUT Untreated)

  • 1: \(S=g_c, Q=0\) (Untreated AND Ineligible)

covariatesnumpy.ndarray

A 2D array of pre-treatment covariates \(X\) for propensity score and outcome regression models. An intercept must be included if desired.

i_weightsnumpy.ndarray, optional

A 1D array of observation weights. If None, weights are uniform. Weights are normalized to have a mean of 1.

est_method{“dr”, “reg”, “ipw”}, default “dr”

Estimation method for each 2-period comparison.

bootbool, default False

Whether to use bootstrap for inference.

boot_type{“multiplier”, “weighted”}, default “multiplier”

Type of bootstrap. Multiplier bootstrap uses Rademacher weights on the influence function; weighted bootstrap re-estimates with exponential weights.

bitersint, default 1000

Number of bootstrap repetitions.

influence_funcbool, default False

Whether to return the influence function.

alphafloat, default 0.05

Significance level for confidence intervals.

random_stateint, Generator, or None, default None

Controls random number generation for bootstrap reproducibility.

Returns:
DDDPanelResult

A NamedTuple containing:

  • att: The DDD point estimate

  • se: Standard error

  • uci, lci: Confidence interval bounds

  • boots: Bootstrap draws (if requested)

  • att_inf_func: Influence function (if requested)

  • did_atts: Individual DiD ATT estimates for each comparison

  • subgroup_counts: Number of units in each subgroup

  • args: Estimation arguments

See also

ddd_mp

Multi-period DDD estimator for staggered adoption.

Notes

The DDD estimator identifies the ATT under the DDD Conditional Parallel Trends assumption (DDD-CPT) from [1], which requires that, conditional on covariates \(X\), the difference in outcome trends between eligible and ineligible units is the same across treatment-enabling groups

\[\begin{split}&\mathbb{E}[Y_t(\infty) - Y_{t-1}(\infty) \mid S=g, Q=1, X] - \mathbb{E}[Y_t(\infty) - Y_{t-1}(\infty) \mid S=g, Q=0, X] \\ &= \mathbb{E}[Y_t(\infty) - Y_{t-1}(\infty) \mid S=g', Q=1, X] - \mathbb{E}[Y_t(\infty) - Y_{t-1}(\infty) \mid S=g', Q=0, X].\end{split}\]

The DR estimator is consistent if, for each of the three DiD components, either the propensity score model or the outcome regression model is correctly specified.

References

[1] (1,2,3)

Ortiz-Villavicencio, M., & Sant’Anna, P. H. C. (2025). Better Understanding Triple Differences Estimators. arXiv preprint arXiv:2505.09942. https://arxiv.org/abs/2505.09942