Commit dd52d27
Round 18: fix sigma_fe to use paper w_{g,t} (not contribution weights)
P1: Round 17's sigma_fe fix still used the contribution weights
w_gt = s * w_paper as if they were the paper's w_{g,t} object. The
paper's Corollary 1 defines w_{g,t} = eps / E_treated[eps], which
does NOT include the observation-share factor in the numerator. The
contribution weights (which include the share factor) are the right
object for the TWFE decomposition itself, but sigma_fe needs the
paper's w_{g,t} centered at 1.
The fix computes w_paper separately:
w_paper = eps_treated / sum(s * eps_treated)
sigma(w) = sqrt(sum(s * (w_paper - 1)^2))
sigma_fe = |beta_fe| / sigma(w)
The exported weights column still contains the contribution weights
(the TWFE decomposition object), not the paper weights.
P2: added test_twfe_diagnostic_hand_checkable_sigma_fe in
TestTWFEDiagnostic with a 4-group 3-period staggered panel.
Asserts beta_fe = 3.5, fraction_negative = 0.0, and
sigma_fe = 6.8641 numerically. This test would have caught both
the Round 17 and pre-Round-17 sigma_fe formula errors.
Test counts: 119 -> 120. Black, ruff clean.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 62b0f93 commit dd52d27
2 files changed
Lines changed: 73 additions & 9 deletions
File tree
- diff_diff
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2091 | 2091 | | |
2092 | 2092 | | |
2093 | 2093 | | |
2094 | | - | |
2095 | | - | |
2096 | | - | |
2097 | | - | |
2098 | | - | |
2099 | | - | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
2100 | 2107 | | |
2101 | 2108 | | |
2102 | 2109 | | |
2103 | | - | |
2104 | | - | |
2105 | | - | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
2106 | 2118 | | |
2107 | 2119 | | |
2108 | 2120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
448 | 500 | | |
449 | 501 | | |
450 | 502 | | |
| |||
0 commit comments