Repository navigation
BUG: Do not let the order of the clusters change the PanelOLS degrees… - #795
Merged
Merged
Conversation
… of freedom With one effect and a clustered covariance, PanelOLS does not count the degrees of freedom of the effect in the debiased covariance if the effect is nested in the clusters (entity effects and clusters by entity, as in Stata). With two cluster variables the function that tests the nesting overwrote its result for each cluster variable, so that only the last variable counted. The standard errors of the same model with the same two cluster variables depended on their order. In the example of the new tests, entity effects with the clusters (entity, time) count the effects and have a standard error of 0.12412 for the first coefficient, and with (time, entity) they do not count them and have 0.11603. The effect is now nested if each of its groups is in one group of every cluster variable, which is the rule of AbsorbingLS, so the result does not depend on the order. An effect that is nested in only one of the two variables is counted. The other way to remove the dependence on the order, to skip an effect that is nested in any variable, would also change entity effects with the clusters (entity, time), the usual two-way clustering. The standard errors change if the effect is nested in the last of two cluster variables but not in the first: entity effects with (time, entity) or (time, industry), and time effects with (entity, time) or (industry, time), where the effects were not counted. They change by the factor sqrt((n - k) / (n - k - N)), which is 7% in the example. One cluster variable, the models with two effects, and the other orders do not change. The tests compare the covariance with the covariance of the regression on the data from which the effect is removed, which is written out in NumPy, and check the order of the variables for entity, time and other effects.
… singletons PanelOLS(..., singletons=False) drops the observations that are alone in a group of an effect, and the clustered covariance with cluster_entity or cluster_time (without the clusters option) raised "IndexError: Boolean index has wrong length: 165 instead of 162". The clusters of the entities and of the periods are made from the data of the model, which no longer has the singletons, and the code then removed the singletons from them using the mask of the singletons, which has a value for each observation before they were dropped. The mask is only needed for the clusters that the user gives, which have a value for each observation that is not missing. It is now applied to those clusters right after they are formatted, so the clusters of the model and the clusters of the user have the same observations. The models without singletons, and the clusters that the user gives with cluster_entity or cluster_time, did not raise and give the same results. The tests compare the results with those of the model estimated from the data from which the singletons were dropped, for entity effects and for entity and time effects, with and without weights and missing values, and with each combination of the clusters.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #795 +/- ##
==========================================
+ Coverage 99.59% 99.62% +0.02%
==========================================
Files 128 141 +13
Lines 24435 28166 +3731
Branches 1820 1981 +161
==========================================
+ Hits 24336 28059 +3723
- Misses 39 41 +2
- Partials 60 66 +6
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 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.
… of freedom
With one effect and a clustered covariance, PanelOLS does not count the degrees of
freedom of the effect in the debiased covariance if the effect is nested in the clusters
(entity effects and clusters by entity, as in Stata). With two cluster variables the
function that tests the nesting overwrote its result for each cluster variable, so that
only the last variable counted. The standard errors of the same model with the same two
cluster variables depended on their order. In the example of the new tests, entity effects
with the clusters (entity, time) count the effects and have a standard error of 0.12412
for the first coefficient, and with (time, entity) they do not count them and have 0.11603.
The effect is now nested if each of its groups is in one group of every cluster variable,
which is the rule of AbsorbingLS, so the result does not depend on the order. An effect
that is nested in only one of the two variables is counted. The other way to remove the
dependence on the order, to skip an effect that is nested in any variable, would also
change entity effects with the clusters (entity, time), the usual two-way clustering.
The standard errors change if the effect is nested in the last of two cluster variables
but not in the first: entity effects with (time, entity) or (time, industry), and time
effects with (entity, time) or (industry, time), where the effects were not counted. They
change by the factor sqrt((n - k) / (n - k - N)), which is 7% in the example. One cluster
variable, the models with two effects, and the other orders do not change.
The tests compare the covariance with the covariance of the regression on the data from
which the effect is removed, which is written out in NumPy, and check the order of the
variables for entity, time and other effects.