Drop a within-entity constant when an intercept is present - #730
Open
shaneraphel wants to merge 1 commit into
Open
shaneraphel wants to merge 1 commit into
shaneraphel wants to merge 1 commit into
Conversation
Entity effects remove it, and adding the grand mean back leaves only roundoff. That roundoff was enough to keep the column, so two encodings of the same variable produced different coefficients.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #730 +/- ##
==========================================
- Coverage 99.54% 99.53% -0.02%
==========================================
Files 101 101
Lines 17450 17476 +26
Branches 1433 1435 +2
==========================================
+ Hits 17371 17394 +23
- Misses 29 31 +2
- Partials 50 51 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With entity effects and an intercept, a regressor that does not vary within an entity is demeaned to zero and then restored as its grand mean.
not_absorbedresidualizes that column on the intercept. Exact arithmetic leaves nothing, but the eigenvalue tolerance is taken relative to the remaining roundoff, so the column is kept. On the bundled wage panel, education is constant for every worker.lwage ~ 1 + educ + EntityEffectswithdrop_absorbed=Truereported 0.13914557037073996. Replacing education by education minus 12 reported -0.36450348040229325. Both p-values were 0. The same model withunionincluded already dropped education and kept union at 0.07468459435240984.drop_absorbed=Falsealready raisedAbsorbingEffectError.The extra check compares the residual norm with the column's own norm, and it returns only the intercept when every non-constant column vanishes. A regression that still has a within-entity regressor uses the existing rank test. After the change both encodings drop the time-invariant column and return the same intercept, 1.6491471921100918.
Fixes #728.
Test plan
pytest linearmodels/tests/panel/test_panel_ols.py::test_drop_absorbed_constant_when_regressor_is_time_invariant linearmodels/tests/panel/test_panel_ols.py::test_fully_absorbed linearmodels/tests/panel/test_panel_ols.py::test_absorbed(4 passed on this branch)unionstays at 0.07468459435240984 and education is still droppeddrop_absorbed=Falsestill raisesAbsorbingEffectError