Skip to content

linearmodels/panel-default-covariance

Rule panel-default-covariance
Pack linearmodels
Severity info
Fix none, edit by hand
Library versions every version

fit without cov_type assumes the errors of one entity are unrelated over time, so it rejects true hypotheses far too often when they are related. Pass cov_type="clustered", cluster_entity=True.

result = PanelOLS(y, X, entity_effects=True).fit()
result = PanelOLS(y, X, entity_effects=True).fit(cov_type="clustered", cluster_entity=True)

The rule reports fit with no cov_type on PanelOLS, PooledOLS, RandomEffects and FirstDifferenceOLS. The default is "unadjusted", the covariance for errors that are homoskedastic and unrelated over time, but the errors of one entity are usually related.

xpd has no automatic fix, so make the change by hand.

In two simulations with a true slope of 0, PanelOLS with entity effects gave p below 0.05 in the following shares of the draws:

Simulation Default cov_type="robust" cov_type="clustered", cluster_entity=True
1,000 draws of 200 entities and 8 periods, with an AR(1) regressor and an AR(1) error within each entity, both with coefficient 0.8 17.3% 16.4% 5.7%
300 entities and 3 periods, with errors that are heteroskedastic and unrelated over time 22.4% 7.1% 5.0%

How far the default is off depends on the data, so the rule is info. It is the rule with the most reports, 372 in 142 of the 950 public files. BetweenOLS has one row for each entity and FamaMacBeth has its own covariance, so both are left alone. A call that states cov_type, also as "unadjusted", is left alone, because the choice is written out.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

fit without cov_type gives the unadjusted covariance, which takes the errors of one entity to be unrelated over time. In a simulation where they were related, it rejected a true coefficient of 0 in 17.3% of 1,000 draws at the 5% level, against 5.7% with cov_type="clustered", cluster_entity=True. Pass those two unless the errors are known to be independent.

Browse the other rules of the linearmodels pack.