Skip to content

Fix some discrepancies with reghdfe/ivreghdfe - #286

Merged
eloualiche merged 4 commits into
FixedEffects:mainfrom
matthieugomez:first-stage-and-dof-parity
Nov 2, 2026
Merged

eloualiche merged 4 commits into
FixedEffects:mainfrom
matthieugomez:first-stage-and-dof-parity

Conversation

@matthieugomez

@matthieugomez matthieugomez commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes discrepancies with reghdfe and bumps the version to 2.2.0.

Changes correcting degrees of freedom and test statistics:

  • Degrees of freedom absorbed by fixed effects: levels redundant across fixed effects were counted (76 instead of 75 with fe(State) + fe(Year) on the Cigar data), and each fixed effect nested in a cluster added exactly one degree of freedom, while reghdfe counts the constant only once and slopes in full. This changes dof_fes, dof_residual, standard errors, the F-statistic, and adjusted R².
  • adjr2: it used n - 1 with slope fixed effects and no constant instead of n.
  • F_kp when over-identified: the correction counted the second-stage regressors, but the residuals come from the first stage, which has one regressor per instrument.
  • F-statistic with a singular covariance matrix: it tests the linearly independent coefficients, instead of reporting values as large as 1e18.

Changes to better handle collinearity:

  • Regressors dropped because of the units of another: with a regressor around 1e12, the constant and the other regressors were dropped. The rank test is now relative to each column's own sum of squares.
  • Regressors dropped because of their mean: year in a panel of five years, or a date, was dropped as collinear with fe(id). The test now compares what remains after absorbing the fixed effects to the variation around the mean, up to the accuracy of the solver.

The fix requires FixedEffects 3.4.1, because the count of redundant levels uses FixedEffects.components. It also requires Vcov 0.8.5 (FixedEffects/Vcov.jl#31).

- Do not count fixed-effect levels that are redundant across fixed effects
- Count fixed effects nested in a cluster only once, for the constant
- Use the first-stage degrees of freedom in F_kp when over-identified
- Require Vcov 0.8.4 and bump version to 2.2.0
@matthieugomez
matthieugomez force-pushed the first-stage-and-dof-parity branch from 87e37a2 to 546e8b3 Compare October 30, 2026 14:18
@matthieugomez matthieugomez changed the title Match Stata in absorbed dof and first-stage F Fix absorbed degrees of freedom and first-stage F Oct 30, 2026
- Do not drop regressors or the constant because of the units of another regressor
- Do not drop regressors as collinear with fixed effects because of their mean
- Estimate models with a constant in deviations from the means
- Count slopes nested in a cluster in the degrees of freedom
- Test only linearly independent coefficients in the F-statistic
- Fix adjr2 with slope fixed effects and no constant
- Require Vcov 0.8.5
@matthieugomez matthieugomez changed the title Fix absorbed degrees of freedom and first-stage F Fix discrepancies with reghdfe and ivreghdfe Oct 30, 2026
@matthieugomez matthieugomez changed the title Fix discrepancies with reghdfe and ivreghdfe Fix some discrepancies with reghdfe/ivreghdfe Oct 30, 2026
@matthieugomez matthieugomez reopened this Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@60f2e1e). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/utils/tss.jl 90.90% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage        ?   96.47%           
=======================================
  Files           ?        9           
  Lines           ?      937           
  Branches        ?        0           
=======================================
  Hits            ?      904           
  Misses          ?       33           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eloualiche
eloualiche merged commit d2ed2c7 into FixedEffects:main Nov 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants