Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEFERRED.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ provenance and AI-review deviation-documentation: a row here (or in
| TwoStageDiD honest/pretrends container admission DEFERRED (decision revised from "widen" during the 2(b) PR-3b plan review): analytical fits carry the joint Gardner-GMM event-study covariance (M-092), but the pre-period coefficients are stage-1 residual MEANS — the reference horizon is dropped from the no-intercept Stage-2 design and the zero anchor row appended mechanically — not contrasts against a reference period, while HonestDiD's Δ^RM/Δ^SD arithmetic hard-codes the `delta_0 = 0` normalization into its boundary/bridge constraints. Admission needs either a Stage-2 re-estimation with the reference horizon in the design or a derived residual-to-reference normalization mapping (+ its variance transform). Both consumers' TypeErrors state the deferral; see the REGISTRY TwoStageDiD Note (d). | `diff_diff/honest_did.py`, `diff_diff/pretrends.py`, `diff_diff/two_stage_aggregation.py` | 2(b) PR-3b | Low |
| RDDensityTest binomial windows test (R rddensity's `bino=` block: exact binomial tests of side counts in shrinking windows around the cutoff): methodology is sourced from Cattaneo, Frandsen & Titiunik (2015, JCI) and Cattaneo, Frandsen & Vazquez-Bare (2017), NOT the reviewed CJM 2020 paper, so implementing it needs its own paper review(s) first (the 2-PR methodology convention). | `diff_diff/rddensity.py` | rddensity PR-B | Low |
| RDDensityTest `rdplotdensity` companion (density plots with pointwise/uniform confidence bands): requires an lpdensity port (Cattaneo, Jansson & Ma 2022 JSS) - a separate estimation surface (evaluation grids, CDF/derivative estimation) well beyond the manipulation test. | `diff_diff/rddensity.py` | rddensity PR-B | Low |
| CBWSDID covariate balancing (`StackedDiD(balance="entropy")`) v1 supports only balanced event windows + `weighting="aggregate"`; unbalanced/ragged panels fail closed (unit-count vs observation-count corrector convention unresolved off balanced panels). Matching-based balancing and the repeated `0→1`/`1→0` episode extension are also deferred. Documented in REGISTRY StackedDiD "Covariate balancing (CBWSDID)" Notes. | `stacked_did.py`, `balancing.py`, REGISTRY | follow-up | Low |
| CBWSDID covariate balancing (`StackedDiD(balance="entropy")`) v1 supports only `weighting="aggregate"`. Matching-based balancing and the repeated `0→1`/`1→0` episode extension are also deferred. Documented in REGISTRY StackedDiD "Covariate balancing (CBWSDID)" Notes. | `stacked_did.py`, `balancing.py`, REGISTRY | follow-up | Low |
| dCDH: Phase-1 per-period placebo `DID_M^pl` has NaN SE (no IF derivation for the per-period aggregation path). Multi-horizon placebos (`L_max ≥ 1`) have valid SE. | `chaisemartin_dhaultfoeuille.py` | #294 | Low |
| dCDH: survey cell-period allocator's post-period attribution is a library convention, not derived from the observation-level survey linearization. MC coverage is empirically close to nominal; a formal derivation (or covariance-aware two-cell alternative) is deferred. Documented in REGISTRY survey IF expansion Note. | `chaisemartin_dhaultfoeuille.py`, REGISTRY | #408 | Medium |
| dCDH by_path: survey-aware backward-horizon (`placebo + predict_het + survey_design`) raises `NotImplementedError` (and `_compute_heterogeneity_test` warn-and-skips to forward-horizon-only heterogeneity) — the Binder TSL cell-period allocator's REGISTRY justification is tied to post-period attribution; backward horizons would put ψ_g mass on a pre-period cell. Needs the pre-period cell allocator derived. | `chaisemartin_dhaultfoeuille.py`, REGISTRY | follow-up | Medium |
Expand Down
28 changes: 24 additions & 4 deletions METHODOLOGY_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,10 @@ and covariate-adjusted specifications.)
2. **Q-weight computation: event-time-specific for aggregate weighting** (`stacked_did.py`,
`_compute_q_weights()`): Changed aggregate Q-weights from unit counts per sub-experiment
to observation counts per (event_time, sub_exp), matching R reference `compute_weights()`.
For balanced panels, results are unchanged. For unbalanced panels, weights now adjust for
varying observation density. Population/sample_share retain unit-count formulas (paper notation).
For balanced panels, results are unchanged. Since the complete-window rule (item 6) every
sub-experiment holds the same units at every event time, so the observation counts equal the
paper's unit counts on ragged input panels too. The three schemes now share one formula on
unit masses (item 7).

3. **Anticipation parameter: reference period and dummies** (`stacked_did.py`, `fit()`):
Reference period now shifts to `e = -1 - anticipation`. Event-time dummies cover the
Expand All @@ -530,8 +532,26 @@ and covariate-adjusted specifications.)
cohort×event-time interactions. Use CallawaySantAnna or ImputationDiD for cohort-level estimates.

5. **n_sub_experiments metadata** (`stacked_did.py`, `fit()`): Now tracks actual built
sub-experiments, not all events in omega_kappa. Warns if any sub-experiments are empty
after data filtering.
sub-experiments, not all events in omega_kappa. An event whose sub-experiment cannot be
built (no treated unit or no clean control observed at every event time of its window) is
dropped with a warning naming the reason and moves from `groups` to `trimmed_groups`.

6. **Complete event windows** (`stacked_did.py`, `_build_sub_experiment()`): a unit enters a
sub-experiment only if it is observed at every event time of the window, as in the paper's
stack (Section 5.1). Ragged panels previously returned shifted estimates with no warning,
because Equation 3 contrasts event-time cell means. Incomplete units are excluded with a
warning (refused under `survey_design=`); duplicate `(unit, time)` rows, a missing or
non-integer `time` and a non-integer `first_treat` raise. Deviation from the R reference
code, which keeps incomplete units, documented in REGISTRY.md.

7. **Equal cohort shares on both arms** (`stacked_did.py`, `_cohort_share_weights()`): the
paper's Table 1 weights treated rows too under population and sample-share weighting; the
library set the treated weight to 1 under every scheme, so those two schemes aggregated the
arms with different shares and the untreated trends did not cancel. Under `survey_design=`
the corrective weights used raw unit counts with the same consequence. One formula now gives
both arms the target share `pi_a`, from survey-weighted unit masses when a survey design is
present, recomputed in each replicate refit. Aggregate weighting without survey weights is
bit-identical.

**Outstanding Concerns:**
- Population/sample_share Q-weights use paper's unit-count formulas (no R reference to validate)
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Related tracking surfaces:
| Re-run the R-dependent benchmark refresh so `docs/benchmarks.rst`'s TWFE "SE Rel Diff 0.1%" cell reflects the 3.9 K_reference convergence (expected 0.1% -> 0.0%; the table is generated, never hand-edited — the movement is noted in the CHANGELOG entry). | `docs/benchmarks.rst`, `benchmarks/R/` | #variance-inventory | Quick | Low |
| `SunAbraham` + `survey_design=` REFUSES (`NotImplementedError`) a panel holding a cohort with no pre-treatment observation, where the unweighted fit excludes the cohort with a warning: dropping its rows under a survey design is naive subsetting, not domain estimation (strata, PSU counts and the design df change). Implement the design-based version - keep the rows and give the excluded cohort no contribution to the other cohorts' estimates or scores - together with the same gap in `WooldridgeDiD` (its domain-estimation row below); one mechanism serves both. | `diff_diff/sun_abraham.py`, `diff_diff/wooldridge.py` | SunAbraham reference PR | Heavy | Low |
| `SunAbraham` + `survey_design=` fails with an array shape mismatch (`operands could not be broadcast together with shapes (720,) (712,)`) when the frame holds a unit whose `first_treat` is negative or missing: the survey arrays are sized to `data`, while `df_reg` drops those rows under `control_group="never_treated"`. Loud, not silent, and pre-existing. Either filter the survey arrays with the same mask or reject such rows up front with a clear message; decide what a negative `first_treat` means first (today it is silently neither treated nor a control). | `diff_diff/sun_abraham.py` | SunAbraham reference PR | Quick | Low |
| `StackedDiD` returns shifted estimates with NO warning on ragged event windows (found by the sibling audit for the SunAbraham reference fix). On a noiseless panel that the balanced fit recovers exactly (`kappa_pre=2, kappa_post=2`, true effect `2 + 0.5 e`): one cohort missing its `e = -1` rows shifts every event-study row by +0.164 (ATT 2.664 for a true 2.5); a cohort with no pre-treatment rows shifts the post rows by -0.164; ONE missing never-treated observation moves them by 0.003. The `balance="entropy"` path already fails closed on ragged windows (REGISTRY StackedDiD); the default path should either handle unit-level missingness inside a sub-experiment (unit fixed effects, or trimming to units observed over the whole window) or fail closed the same way. Establish what Wing, Freedman and Hollingsworth prescribe before choosing. | `diff_diff/stacked_did.py`, `docs/methodology/REGISTRY.md` | SunAbraham reference PR | Mid | Medium |
| `StackedDiD` + `survey_design=` does not retain the full survey design. The design is re-resolved on the stacked rows, so the PSUs and strata of every unit outside the stack leave the Taylor-linearized meat and `df_survey` with no warning (balanced panel, 120 single-unit PSUs in 3 strata, one cohort trimmed by IC1 under `control_group="never_treated"`: 90 PSUs in the fit, `df_survey` 87 where the full design gives 117). For the same reason two cases are REFUSED (`NotImplementedError`) under a survey design where the unweighted fit proceeds with a warning: a unit not observed across its event window, and an adoption event left without complete units. Implement domain estimation - keep the full design and give out-of-stack PSUs zero scores (REGISTRY *Subpopulation Analysis*) - then lift both refusals. | `diff_diff/stacked_did.py`, `diff_diff/survey.py` | StackedDiD complete-window PR | Mid | Medium |
| Define `N_g` (W2025 Eqs. 7.4/7.6) for UNBALANCED panels where comparison-support filtering removes every observation of some units in an estimated cohort, then replace the fail-closed guard with the defined behavior. `_n_g_per_cohort` is read off the final sample, so those units vanish from the cohort-share weights; measured on a cohort supplied with 100 units of which 90 appear only at a dropped period, `aggregate(weights="cohort_share")` moves 1.8078 -> 3.8157. The paper assumes a balanced panel and does not say whether `N_g` counts the supplied cohort or the surviving units, and the two disagree materially, so `aggregate` currently raises naming the cohorts and counts ([M-125]); `weights="cell"` is unaffected and balanced panels never trip it. Settle the estimand (likely: count the supplied cohort, since ATT(g,t) is a cohort-level quantity, but that weights units with no retained observation) and gate with a test computing Eq. 7.4 by hand on unequal cohort sizes. | `diff_diff/wooldridge_results.py`, `diff_diff/wooldridge.py` | #729-followup | Mid | Medium |
| `WooldridgeDiD` + `survey_design=` does not support DOMAIN ESTIMATION, so BOTH row-deleting paths are currently REFUSED (`NotImplementedError`, all three methods) rather than performed: unidentified-cohort exclusion ([M-123]) and comparison-support period filtering ([M-125]). One fix unblocks both. Implementing it properly means zero-padding the excluded rows' weights while retaining strata/PSU/FPC, per REGISTRY *Subpopulation Analysis (Phase 6)* / Lumley (2004) 3.4, so TSL variance and `df_survey = n_PSU - n_strata` use the full design (naive deletion measured 22 -> 14 on a two-stratum panel). `SurveyDesign.subpopulation()` already implements the contract and SpilloverDiD Wave E.3 is the in-repo precedent; the blocker is that the weighted within-transform rejects zero-weight units, shared machinery behind 7 estimators. Landing it would turn both refusals back into supported fits. Gate with a `SurveyDesign.subpopulation()` parity test on ATT, TSL SE and survey df where the excluded cohort exhausts a PSU. | `diff_diff/wooldridge.py`, `diff_diff/utils.py` | #724-codex-R4/R5 | Heavy | Medium |
| `WooldridgeDiD` REFUSES a fit whose only treatment cells fall inside the anticipation window, discarding estimates it successfully computed. `_require_estimable_overall_att` ([M-124]) raises when no cell has `t >= g`, because the overall ATT averages only `t >= g` (W2025 excludes anticipation leads) while cells from `t >= g - anticipation` are ESTIMATED. For a cohort never observed at or after its own treatment date, those anticipation-window ATT(g, t) are real, identified estimates and are thrown away with the fit. **The refusal is a stopgap for the missing estimand semantics, not the intended end state.** Real fix: decide what such a fit should return — most likely the per-cell ATT(g, t) plus an overall that is explicitly undefined with a stated reason (not a bare NaN, per the no-silent-NaN convention) — then relax the guard to that. Needs a REGISTRY note defining the estimand and an `aggregate()` story for the anticipation-only case. | `diff_diff/wooldridge.py` | #724-codex-R2 | Mid | Medium |
Expand Down
59 changes: 31 additions & 28 deletions benchmarks/R/benchmark_survey_estimators.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,40 +323,43 @@ rownames(stacked) <- NULL
n_stacked <- nrow(stacked)
cat(sprintf(" Stacked dataset: %d observations\n", n_stacked))

# Step 2: Compute Q-weights (sample_share)
# Count distinct units per sub-experiment
N_D <- sapply(sub_experiments, function(df) length(unique(df$unit[df$D_sa == 1])))
N_C <- sapply(sub_experiments, function(df) length(unique(df$unit[df$D_sa == 0])))
N_Omega_D <- sum(N_D)
N_Omega_C <- sum(N_C)
N_grand <- N_Omega_D + N_Omega_C

cat(sprintf(" N_D per sub-exp: %s\n", paste(N_D, collapse = ", ")))
cat(sprintf(" N_C per sub-exp: %s\n", paste(N_C, collapse = ", ")))
cat(sprintf(" N_Omega_D = %d, N_Omega_C = %d, N_grand = %d\n",
N_Omega_D, N_Omega_C, N_grand))

q_control <- setNames(numeric(length(cohorts)), as.character(cohorts))
for (a_str in names(N_D)) {
n_c <- N_C[a_str]
n_d <- N_D[a_str]
if (n_c == 0 || N_Omega_C == 0) {
q_control[a_str] <- 1.0
} else {
control_share <- n_c / N_Omega_C
sample_share <- (n_d + n_c) / N_grand
q_control[a_str] <- sample_share / control_share
}
# Step 2: Compute corrective Q-weights (sample_share)
# Both arms must aggregate the sub-experiments with the SAME shares, otherwise
# the untreated trends do not cancel (Wing et al. 2024, Section 5.3). Under a
# survey design the shares are formed from survey-weighted unit masses
# (weights are constant within a unit):
# W_a^D = sum of treated units' weights, W_a^C = sum of controls' weights
# pi_a = (W_a^D + W_a^C) / (W^D + W^C) (sample_share target)
# Q = pi_a / (W_a^D / W^D) for treated rows (Table 1 treatment weight)
# Q = pi_a / (W_a^C / W^C) for control rows
unit_mass <- function(df, d) {
u <- df[df$D_sa == d, ]
u <- u[!duplicated(u$unit), ]
sum(u$weight)
}
W_D <- sapply(sub_experiments, unit_mass, d = 1)
W_C <- sapply(sub_experiments, unit_mass, d = 0)
W_Omega_D <- sum(W_D)
W_Omega_C <- sum(W_C)

cat(sprintf(" W_D per sub-exp: %s\n", paste(sprintf("%.6f", W_D), collapse = ", ")))
cat(sprintf(" W_C per sub-exp: %s\n", paste(sprintf("%.6f", W_C), collapse = ", ")))

target_share <- (W_D + W_C) / (W_Omega_D + W_Omega_C)
q_treated <- target_share / (W_D / W_Omega_D)
q_control <- target_share / (W_C / W_Omega_C)
cat(sprintf(" Q-weights (treated): %s\n",
paste(sprintf("%s=%.6f", names(q_treated), q_treated), collapse = ", ")))
cat(sprintf(" Q-weights (control): %s\n",
paste(sprintf("%s=%.6f", names(q_control), q_control), collapse = ", ")))

# Assign Q-weights: treated=1, control=q_control[sub_exp]
stacked$Q_weight <- 1.0
stacked$Q_weight <- NA_real_
for (a_str in names(q_control)) {
mask <- stacked$sub_exp == as.numeric(a_str) & stacked$D_sa == 0
stacked$Q_weight[mask] <- q_control[a_str]
in_a <- stacked$sub_exp == as.numeric(a_str)
stacked$Q_weight[in_a & stacked$D_sa == 1] <- q_treated[a_str]
stacked$Q_weight[in_a & stacked$D_sa == 0] <- q_control[a_str]
}
stopifnot(!anyNA(stacked$Q_weight))

# Step 3: Compose Q x survey weight, normalize
stacked$composed_weight <- stacked$Q_weight * stacked$weight
Expand Down
20 changes: 20 additions & 0 deletions benchmarks/R/generate_cbwsdid_golden.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ m <- cbwsdid(
)
qoi <- cbwsdid_qoi(m, type = "dynamic")

# Ragged copy of the same panel: units 1-5 (cohort 5) lose their t = 6 row and
# units 55-59 (never-treated) lose their t = 5 row. cbwsdid builds each
# sub-experiment from the units observed across the whole event window, which is
# the complete-window rule StackedDiD applies; this block pins that agreement.
ragged <- df[!((df$unit %in% 1:5 & df$time == 6) | (df$unit %in% 55:59 & df$time == 5)), ]
m_ragged <- cbwsdid(
data = ragged, y = "y", d = "d", id = c("unit", "time"),
kappa = c(-2, 2), design = "absorbing", post_path = "stable",
refinement.method = "weightit", covs.formula = ~x,
refinement.args = list(method = "ebal"), pooled = TRUE
)
qoi_ragged <- cbwsdid_qoi(m_ragged, type = "dynamic")

golden <- list(
meta = list(
package = "cbwsdid",
Expand All @@ -47,6 +60,13 @@ golden <- list(
std_error = as.numeric(qoi$std.error)
)
)
golden$dynamic_ragged <- list(
dropped_rows = "unit in 1:5 & time == 6; unit in 55:59 & time == 5",
nobs = as.integer(m_ragged$nobs),
event_time = as.integer(qoi_ragged$et),
estimate = as.numeric(qoi_ragged$estimate),
std_error = as.numeric(qoi_ragged$std.error)
)
write_json(golden, out_json, auto_unbox = TRUE, digits = 15, pretty = TRUE)
cat("wrote", out_json, "\n")
print(data.frame(et = qoi$et, estimate = qoi$estimate, se = qoi$std.error))
7 changes: 7 additions & 0 deletions benchmarks/data/cbwsdid_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
"event_time": [-2, 0, 1, 2],
"estimate": [0.008614905402558678, 1.998507474812239, 2.000435324046538, 1.977837212056277],
"std_error": [0.05870423491347857, 0.05704878175034945, 0.1113623933607992, 0.1700804801053713]
},
"dynamic_ragged": {
"dropped_rows": "unit in 1:5 & time == 6; unit in 55:59 & time == 5",
"nobs": 1185,
"event_time": [-2, 0, 1, 2],
"estimate": [0.01244907143498961, 2.003124493838106, 2.004966724053774, 1.982689462926543],
"std_error": [0.06293179799467032, 0.06042498588243073, 0.1177882246009692, 0.1807105370549422]
}
}
Loading
Loading