Skip to content

Commit cb2d885

Browse files
igerberclaude
andcommitted
Thread survey_design through bacon_decompose() and triple_difference() convenience functions from PR #226 review (round 15)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4604bad commit cb2d885

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

diff_diff/bacon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ def bacon_decompose(
10431043
time: str,
10441044
first_treat: str,
10451045
weights: str = "approximate",
1046+
survey_design: object = None,
10461047
) -> BaconDecompositionResults:
10471048
"""
10481049
Convenience function for Goodman-Bacon decomposition.
@@ -1119,4 +1120,4 @@ def bacon_decompose(
11191120
CallawaySantAnna : Robust estimator that avoids forbidden comparisons
11201121
"""
11211122
decomp = BaconDecomposition(weights=weights)
1122-
return decomp.fit(data, outcome, unit, time, first_treat)
1123+
return decomp.fit(data, outcome, unit, time, first_treat, survey_design=survey_design)

diff_diff/triple_diff.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ def triple_difference(
17021702
cluster: Optional[str] = None,
17031703
alpha: float = 0.05,
17041704
rank_deficient_action: str = "warn",
1705+
survey_design: object = None,
17051706
) -> TripleDifferenceResults:
17061707
"""
17071708
Estimate Triple Difference (DDD) treatment effect.
@@ -1776,4 +1777,5 @@ def triple_difference(
17761777
partition=partition,
17771778
time=time,
17781779
covariates=covariates,
1780+
survey_design=survey_design,
17791781
)

tests/test_survey_phase3.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,21 @@ def test_exact_weights_survey_weighted(self, staggered_survey_data):
425425
diffs = [abs(exact_weights[k] - approx_weights[k]) for k in common_keys]
426426
assert max(diffs) > 1e-10, "Exact and approximate weights should differ"
427427

428+
def test_convenience_function(self, staggered_survey_data):
429+
"""bacon_decompose() convenience function threads survey_design."""
430+
from diff_diff.bacon import bacon_decompose
431+
432+
sd = SurveyDesign(weights="weight")
433+
result = bacon_decompose(
434+
staggered_survey_data,
435+
"outcome",
436+
"unit",
437+
"time",
438+
"first_treat",
439+
survey_design=sd,
440+
)
441+
assert result.survey_metadata is not None
442+
428443

429444
# =============================================================================
430445
# TripleDifference
@@ -555,6 +570,22 @@ def test_reg_with_covariates_survey(self, ddd_survey_data):
555570
# Survey df should be used for inference
556571
assert result.survey_metadata.df_survey is not None
557572

573+
def test_convenience_function(self, ddd_survey_data):
574+
"""triple_difference() convenience function threads survey_design."""
575+
from diff_diff.triple_diff import triple_difference
576+
577+
sd = SurveyDesign(weights="weight")
578+
result = triple_difference(
579+
ddd_survey_data,
580+
"outcome",
581+
"group",
582+
"partition",
583+
"time",
584+
estimation_method="reg",
585+
survey_design=sd,
586+
)
587+
assert result.survey_metadata is not None
588+
558589

559590
# =============================================================================
560591
# ContinuousDiD

0 commit comments

Comments
 (0)