moderndid.construct_original_cs#

moderndid.construct_original_cs(betahat, sigma, num_pre_periods, num_post_periods, l_vec=None, alpha=0.05)[source]#

Construct original (non-robust) confidence set.

Constructs a standard confidence interval for the parameter of interest assuming the parallel trends assumption holds exactly, i.e., \(\delta_{post} = 0\). This provides a baseline for comparison with robust confidence intervals from sensitivity analysis. The original confidence set uses only the post-treatment coefficients and their covariance to construct a standard normal-based interval.

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 of weights for parameter of interest. Default is first post-period effect.

alphafloat, default=0.05

Significance level.

Returns:
OriginalCSResult

NamedTuple with lb, ub, method=”Original”, delta=None.

Examples

To use this function directly, we need to compute an event study and extract the estimates and covariance matrix.

In [1]: import numpy as np
   ...: from moderndid import att_gt, aggte, load_mpdta
   ...: from moderndid.didhonest import construct_original_cs
   ...: df = load_mpdta()
   ...: gt_result = att_gt(
   ...:     data=df,
   ...:     yname="lemp",
   ...:     tname="year",
   ...:     gname="first.treat",
   ...:     idname="countyreal",
   ...:     est_method="dr",
   ...:     boot=False
   ...: )
   ...: es_result = aggte(gt_result, type="dynamic")
   ...: 

Now we can extract the estimates and covariance matrix.

In [2]: influence_func = es_result.influence_func
   ...: event_times = es_result.event_times
   ...: ref_idx = np.where(event_times == -1)[0][0]
   ...: att_no_ref = np.delete(es_result.att_by_event, ref_idx)
   ...: influence_no_ref = np.delete(influence_func, ref_idx, axis=1)
   ...: n = influence_no_ref.shape[0]
   ...: vcov = influence_no_ref.T @ influence_no_ref / (n * n)
   ...: num_pre = int(np.sum(np.delete(event_times, ref_idx) < -1))
   ...: num_post = len(att_no_ref) - num_pre
   ...: 

Finally, we can construct the original confidence interval for the first post-treatment effect.

In [3]: original_ci = construct_original_cs(
   ...:     betahat=att_no_ref,
   ...:     sigma=vcov,
   ...:     num_pre_periods=num_pre,
   ...:     num_post_periods=num_post
   ...: )
   ...: original_ci
   ...: 
Out[3]: OriginalCSResult(lb=np.float64(-0.043111064411112364), ub=np.float64(0.0032474308325936008), method='Original', delta=None)