moderndid.compute_conditional_cs_rm#

moderndid.compute_conditional_cs_rm(betahat, sigma, num_pre_periods, num_post_periods, l_vec=None, m_bar=0, alpha=0.05, hybrid_flag='LF', hybrid_kappa=None, return_length=False, post_period_moments_only=True, grid_points=1000, grid_lb=None, grid_ub=None, seed=None)[source]#

Compute conditional confidence set for \(\Delta^{RM}(\bar{M})\).

Computes the confidence set by taking the union over all choices of reference period \(s\) and sign restrictions (+)/(-).

The relative magnitudes restriction \(\Delta^{RM}(\bar{M})\) is defined in Section 2.4.1 of [2] as

\[\Delta^{RM}(\bar{M}) = \{\delta: \forall t \ge 0, |\delta_{t+1} - \delta_t| \le \bar{M} \cdot \max_{s<0} |\delta_{s+1} - \delta_s|\}.\]

This restriction formalizes that post-treatment violations of parallel trends are not excessively larger than pre-treatment violations. As shown in footnote 9 of [2], \(\Delta^{RM}(\bar{M})\) can be written as a finite union of polyhedra, which allows for tractable computation.

The confidence set is constructed based on Lemma 2.2 in [2], which states that a valid confidence set for a union of sets is the union of the confidence sets for each component. Thus, we compute

\[\mathcal{C}_n(\Delta^{RM}(\bar{M})) = \bigcup_{s<0, \text{sign} \in \{+,-\}} \mathcal{C}_n(\Delta^{RM}_{s, \text{sign}}(\bar{M})),\]

where \(\Delta^{RM}_{s, \text{sign}}(\bar{M})\) corresponds to the polyhedron where the maximum pre-treatment violation occurs at period \(s\) with a given sign.

Parameters:
betahatnumpy.ndarray

Estimated event study coefficients.

sigmanumpy.ndarray

Covariance matrix of betahat.

num_pre_periodsint

Number of pre-treatment periods.

num_post_periodsint

Number of post-treatment periods.

l_vecnumpy.ndarray, optional

Vector defining parameter of interest \(\theta = l'\tau_{post}\). If None, defaults to first post-period, \(\tau_{post,1}\).

m_barfloat, default=0

Relative magnitude parameter \(\bar{M}\). Controls how much larger post-treatment violations can be relative to pre-treatment violations.

alphafloat, default=0.05

Significance level.

hybrid_flag{‘LF’, ‘ARP’}, default=’LF’

Type of hybrid test.

hybrid_kappafloat, optional

First-stage size for hybrid test. If None, defaults to alpha/10.

return_lengthbool, default=False

If True, return only the length of the confidence interval.

post_period_moments_onlybool, default=True

If True, use only post-period moments for ARP test.

grid_pointsint, default=1000

Number of grid points for confidence interval search.

grid_lbfloat, optional

Lower bound for grid search. If None, calculated as gridoff - gridhalf, where gridoff = betahat_post @ l_vec and gridhalf = (m_bar * sum(1:T_post * \(\ell_{vec}\)) * maxpre) + (20 * sd_theta).

grid_ubfloat, optional

Upper bound for grid search. If None, calculated as gridoff + gridhalf, using the same formula as grid_lb.

seedint, optional

Random seed for reproducibility.

Returns:
dict or float

If return_length is False, returns dict with ‘grid’ and ‘accept’ arrays. If return_length is True, returns the length of the confidence interval.

Notes

The confidence set is constructed using the moment inequality approach from Section 3 of [2]. Testing \(H_0: \theta = \bar{\theta}\) for \(\delta \in \Delta\) is equivalent to testing a system of moment inequalities with linear nuisance parameters, as shown in (12) and (13) of [2]. The conditional and hybrid tests from [1] are used to handle the computational challenge of high-dimensional nuisance parameters by exploiting the linear structure.

As detailed in footnote 9 of [2], \(\Delta^{RM}(\bar{M})\) is decomposed into a finite union of polyhedra

\[\Delta^{RM}(\bar{M}) = \bigcup_{s<0} (\Delta_{s,+}^{RM}(\bar{M}) \cup \Delta_{s,-}^{RM}(\bar{M})),\]

where

\[\Delta_{s,+}^{RM}(\bar{M}) = \{\delta: \forall t \ge 0, |\delta_{t+1} - \delta_t| \le \bar{M}(\delta_{s+1} - \delta_s)\},\]

and

\[\Delta_{s,-}^{RM}(\bar{M}) = \{\delta: \forall t \ge 0, |\delta_{t+1} - \delta_t| \le -\bar{M}(\delta_{s+1} - \delta_s)\}.\]

References

[1]

Andrews, I., Roth, J., & Pakes, A. (2021). Inference for linear conditional moment inequalities. Review of Economic Studies.

[2] (1,2,3,4,5,6)

Rambachan, A., & Roth, J. (2023). A more credible approach to parallel trends. Review of Economic Studies, 90(5), 2555-2591.