Skip to content

Commit cb3f815

Browse files
igerberclaude
andcommitted
Refactor RC IFs to R's psi convention, fix HonestDiD VCV subsetting
Restructure _outcome_regression_rc, _ipw_estimation_rc, _doubly_robust_rc to compute leading IF terms in R's unnormalized psi convention (using mean_w_* = sum_w_*/n_all normalizers matching R's mean()), then convert to library phi = psi/n_all at the boundary. Makes DRDID correspondence explicit with R variable name comments. Fix HonestDiD event_study_vcov subsetting: when filtering NaN-SE event times, subset the VCV matrix to match the surviving rel_times (was using the full unfiltered matrix, causing dimension mismatch on interior drops). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c2f8fdc commit cb3f815

2 files changed

Lines changed: 237 additions & 163 deletions

File tree

diff_diff/honest_did.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,16 @@ def _extract_event_study_params(
664664
# Use full event-study VCV if available (Phase 7d),
665665
# otherwise fall back to diagonal from SEs
666666
if hasattr(results, "event_study_vcov") and results.event_study_vcov is not None:
667-
# event_study_vcov is indexed by sorted rel_times
668-
sigma = results.event_study_vcov
667+
vcov = results.event_study_vcov
668+
# VCV is indexed by ALL event times from aggregation;
669+
# rel_times may be a filtered subset (NaN-SE times dropped).
670+
# Subset VCV to match the surviving rel_times.
671+
all_event_times = sorted(results.event_study_effects.keys())
672+
if vcov.shape[0] == len(all_event_times) and len(rel_times) < len(all_event_times):
673+
idx = [all_event_times.index(t) for t in rel_times]
674+
sigma = vcov[np.ix_(idx, idx)]
675+
else:
676+
sigma = vcov
669677
else:
670678
sigma = np.diag(np.array(ses) ** 2)
671679

0 commit comments

Comments
 (0)