Skip to content

Commit e9995ef

Browse files
igerberclaude
andcommitted
HonestDiD: validate full grid around reference period, not just within-block
Check that post_times[0] - pre_times[-1] == 2 (exactly one gap for the omitted reference period). Catches missing e=0 or missing boundary horizons that the within-block check missed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c529053 commit e9995ef

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

diff_diff/honest_did.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,21 @@ def _extract_event_study_params(
699699
else:
700700
sigma = np.diag(np.array(ses) ** 2)
701701

702-
# Validate pre and post blocks are each consecutive
703-
# (the gap between last pre and first post is the omitted
704-
# reference period and is expected)
705-
has_gap = False
702+
# Validate the full event-time grid is consecutive around
703+
# the omitted reference period (exactly one gap allowed).
704+
# R's HonestDiD refuses non-consecutive grids.
705+
if pre_times and post_times:
706+
# Expected: pre_times[-1] + 1 = reference, reference + 1 = post_times[0]
707+
# So post_times[0] - pre_times[-1] should be exactly 2
708+
ref_gap = post_times[0] - pre_times[-1]
709+
has_gap = ref_gap != 2
710+
elif pre_times:
711+
has_gap = False # only pre, no ref gap to check
712+
elif post_times:
713+
has_gap = False # only post, no ref gap to check
714+
else:
715+
has_gap = False
716+
# Also check within-block consecutiveness
706717
for block in [pre_times, post_times]:
707718
if len(block) >= 2:
708719
for i in range(len(block) - 1):
@@ -711,12 +722,13 @@ def _extract_event_study_params(
711722
break
712723
if has_gap:
713724
raise ValueError(
714-
"HonestDiD requires a consecutive event-time grid. "
715-
f"Retained pre-periods {pre_times} and/or post-periods "
716-
f"{post_times} have interior gaps. This can happen when "
717-
"some event-study horizons have non-finite SEs. Ensure "
718-
"all event-study periods have valid estimates, or use "
719-
"balance_e to restrict to a balanced subset."
725+
"HonestDiD requires a consecutive event-time grid "
726+
"around the omitted reference period. Retained "
727+
f"pre-periods {pre_times} and post-periods "
728+
f"{post_times} have gaps. This can happen when "
729+
"some event-study horizons have non-finite SEs. "
730+
"Ensure all event-study periods have valid estimates, "
731+
"or use balance_e to restrict to a balanced subset."
720732
)
721733

722734
# Extract survey df

0 commit comments

Comments
 (0)