Skip to content

Commit 8a757b1

Browse files
igerberclaude
andcommitted
Propagate replicate metadata in CS unit-level survey collapse
CallawaySantAnna._collapse_survey_to_unit_level() now carries through replicate_weights (collapsed via groupby().first()), replicate_method, fay_rho, n_replicates, and replicate_strata. Previously these fields were dropped, causing replicate-weight fits to silently fall back to non-replicate aggregation SEs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a8b3e4c commit 8a757b1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

diff_diff/staggered.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,20 @@ def _collapse_survey_to_unit_level(resolved_survey, df, unit_col, all_units):
379379
.values
380380
)
381381

382+
# Collapse replicate weights to unit level (same groupby pattern)
383+
rep_weights_unit = None
384+
if resolved_survey.replicate_weights is not None:
385+
R = resolved_survey.replicate_weights.shape[1]
386+
rep_weights_unit = np.zeros((n_units, R))
387+
for r in range(R):
388+
rep_weights_unit[:, r] = (
389+
pd.Series(resolved_survey.replicate_weights[:, r], index=df.index)
390+
.groupby(df[unit_col])
391+
.first()
392+
.reindex(all_units)
393+
.values
394+
)
395+
382396
return ResolvedSurveyDesign(
383397
weights=weights_unit.astype(np.float64),
384398
weight_type=resolved_survey.weight_type,
@@ -388,6 +402,11 @@ def _collapse_survey_to_unit_level(resolved_survey, df, unit_col, all_units):
388402
n_strata=resolved_survey.n_strata,
389403
n_psu=resolved_survey.n_psu,
390404
lonely_psu=resolved_survey.lonely_psu,
405+
replicate_weights=rep_weights_unit,
406+
replicate_method=resolved_survey.replicate_method,
407+
fay_rho=resolved_survey.fay_rho,
408+
n_replicates=resolved_survey.n_replicates,
409+
replicate_strata=resolved_survey.replicate_strata,
391410
)
392411

393412
def _precompute_structures(

0 commit comments

Comments
 (0)