Commit c0c7e5a
Fix M2 gradient scaling: use np.sum instead of np.mean over control subsets
The M2 gradient terms in PS nuisance corrections used np.mean() over
control subsets, introducing an extra 1/n_c divisor. R's DRDID computes
M2 as colMeans() over the full n-sample (zeros for treated), then divides
by mean(w.cont) — the n's cancel, giving sum(w*resid*X)/sum(w). With
our Hajek-normalized weights (w_norm = w/sum(w)), np.sum(w_norm*resid*X)
directly yields sum(w*resid*X)/sum(w), matching R after cancellation.
The single /n on the correction line remains as the psi-to-phi conversion.
Applied at all 5 PS correction sites (panel survey IPW/DR, panel
non-survey DR, RCS IPW, RCS DR).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 43c5547 commit c0c7e5a
1 file changed
Lines changed: 10 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2072 | 2072 | | |
2073 | 2073 | | |
2074 | 2074 | | |
2075 | | - | |
2076 | | - | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
2077 | 2079 | | |
2078 | 2080 | | |
2079 | 2081 | | |
| |||
2331 | 2333 | | |
2332 | 2334 | | |
2333 | 2335 | | |
2334 | | - | |
| 2336 | + | |
2335 | 2337 | | |
2336 | 2338 | | |
2337 | 2339 | | |
| |||
2394 | 2396 | | |
2395 | 2397 | | |
2396 | 2398 | | |
2397 | | - | |
| 2399 | + | |
2398 | 2400 | | |
2399 | 2401 | | |
2400 | 2402 | | |
| |||
3152 | 3154 | | |
3153 | 3155 | | |
3154 | 3156 | | |
3155 | | - | |
3156 | | - | |
| 3157 | + | |
| 3158 | + | |
3157 | 3159 | | |
3158 | 3160 | | |
3159 | 3161 | | |
| |||
3469 | 3471 | | |
3470 | 3472 | | |
3471 | 3473 | | |
3472 | | - | |
| 3474 | + | |
3473 | 3475 | | |
3474 | 3476 | | |
3475 | 3477 | | |
3476 | 3478 | | |
3477 | | - | |
| 3479 | + | |
3478 | 3480 | | |
3479 | 3481 | | |
3480 | 3482 | | |
| |||
0 commit comments