moderndid.compute_flci#
- moderndid.compute_flci(beta_hat, sigma, smoothness_bound, n_pre_periods, n_post_periods, post_period_weights=None, num_points=100, alpha=0.05, seed=0)[source]#
Compute fixed-length confidence intervals under smoothness restrictions.
Constructs fixed-length confidence intervals (FLCIs) based on affine estimators that are valid for the linear combination \(l'\tau_{post}\) under the restriction that the underlying trend \(\delta\) lies in the smoothness constraint set \(\Delta^{SD}(M)\).
The FLCI takes the form
\[\mathcal{C}_{\alpha,n}(a, v, \chi) = (a + v'\hat{\beta}_n) \pm \chi,\]where \(a\) is a scalar, \(v \in \mathbb{R}^{\underline{T}+\bar{T}}\) is a weight vector, and \(\chi\) is the half-length of the confidence interval.
The optimization minimizes \(\chi\) subject to the coverage requirement in the finite-sample normal model. The smallest value of \(\chi\) that satisfies coverage is
\[\chi_n(a, v; \alpha) = \sigma_{v,n} \cdot cv_{\alpha}(\bar{b}(a, v) / \sigma_{v,n}),\]where \(\sigma_{v,n} = \sqrt{v'\Sigma_n v}\) and \(cv_{\alpha}(t)\) denotes the \(1-\alpha\) quantile of the folded normal distribution \(|N(t, 1)|\).
- Parameters:
- beta_hat
numpy.ndarray Vector of estimated event study coefficients \(\hat{\beta}\). First n_pre_periods elements are pre-treatment, remainder are post-treatment.
- sigma
numpy.ndarray Covariance matrix of estimated coefficients \(\Sigma\).
- smoothness_bound
float Smoothness parameter \(M\) for the restriction set \(\Delta^{SD}(M)\). Bounds the second differences: \(|\delta_{t-1} - 2\delta_t + \delta_{t+1}| \leq M\).
- n_pre_periods
int Number of pre-treatment periods \(T_{pre}\).
- n_post_periods
int Number of post-treatment periods \(T_{post}\).
- post_period_weights
numpy.ndarray, optional Weight vector \(\ell_{post}\) for post-treatment periods. Default is the first post-period (i.e., \(\ell_{post} = e_1\)).
- num_points
int, default=100 Number of points for grid search in optimization.
- alpha
float, default=0.05 Significance level for confidence interval.
- seed
int, default=0 Random seed for reproducibility.
- beta_hat
- Returns:
FLCIResultNamedTuple containing:
flci: Tuple of (lower, upper) confidence interval bounds
optimal_vec: Optimal weight vector \((\ell_{pre}, \ell_{post})\) for all periods
optimal_pre_period_vec: Optimal weights \(\ell_{pre}\) for pre-periods
optimal_half_length: Half-length of the confidence interval
smoothness_bound: Smoothness parameter \(M\) used
status: Optimization status
Notes
The FLCI is computed by solving a nested optimization problem. For each candidate standard deviation \(h\), we find the worst-case bias under \(\Delta^{SD}(M)\), then choose \(h\) to minimize the resulting confidence interval length.
For \(\Delta^{SD}(M)\) with \(\theta = \tau_1\), the affine estimator used by the optimal FLCI takes the form in [1]
\[a + v'\hat{\beta}_n = \hat{\beta}_{n,1} - \sum_{s=-\underline{T}+1}^{0} w_s(\hat{\beta}_{n,s} - \hat{\beta}_{n,s-1}),\]where the weights \(w_s\) sum to one (but may be negative). This estimator adjusts the event-study coefficient for \(t=1\) by an estimate of the differential trend between \(t=0\) and \(t=1\) formed by taking a weighted average of the differential trends in periods prior to treatment.
Under convexity and centrosymmetry conditions on the identified set, FLCIs achieve near-optimal expected length in finite samples. When \(\alpha = 0.05\), the expected length of the shortest possible confidence set that satisfies coverage is at most 28% shorter than the FLCI.
References
[1]Rambachan, A., & Roth, J. (2023). A more credible approach to parallel trends. Review of Economic Studies, 90(5), 2555-2591.