Skip to content

Commit a8e2a20

Browse files
igerberclaude
andcommitted
Reject fweight for StackedDiD survey and add regression test from PR #226 review (round 17)
Q-weight composition produces non-integer composed weights, breaking frequency-weight semantics. Raise ValueError for weight_type='fweight'. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent efc09f9 commit a8e2a20

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

diff_diff/stacked_did.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ def fit(
243243
_resolve_survey_for_fit(survey_design, data, "analytical")
244244
)
245245

246+
# Reject fweight — Q-weight composition is ratio-valued and breaks
247+
# frequency-weight semantics (fweights must be integers)
248+
if (
249+
survey_design is not None
250+
and hasattr(survey_design, "weight_type")
251+
and survey_design.weight_type == "fweight"
252+
):
253+
raise ValueError(
254+
"StackedDiD does not support frequency weights (weight_type='fweight') "
255+
"because Q-weight composition produces non-integer composed weights. "
256+
"Use weight_type='pweight' (default) or 'aweight' instead."
257+
)
258+
246259
# Collect survey design column names for propagation through sub-experiments
247260
survey_cols: List[str] = []
248261
if survey_design is not None and isinstance(survey_design, SurveyDesign):

tests/test_survey_phase3.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ def test_summary_includes_survey(self, staggered_survey_data):
328328
)
329329
assert "Survey Design" in result.summary()
330330

331+
def test_fweight_rejected(self, staggered_survey_data):
332+
"""StackedDiD should reject fweight since Q-weight composition breaks it."""
333+
from diff_diff import StackedDiD
334+
335+
sd = SurveyDesign(weights="weight", weight_type="fweight")
336+
with pytest.raises(ValueError, match="fweight"):
337+
StackedDiD().fit(
338+
staggered_survey_data,
339+
"outcome",
340+
"unit",
341+
"time",
342+
"first_treat",
343+
survey_design=sd,
344+
)
345+
331346

332347
# =============================================================================
333348
# BaconDecomposition

0 commit comments

Comments
 (0)