linearmodels.panel.results.RandomEffectsResults.hausman¶
-
RandomEffectsResults.hausman(other: PanelResults, include_constant: bool =
False, sigmamore: bool =False, sigmaless: bool =False) HausmanTestResults[source]¶ Hausman specification test against results from a consistent model.
- Parameters:¶
- other: PanelResults¶
Results from a model that is consistent whether or not the null hypothesis is true, typically a fixed effects (entity effects) model estimated using the same observations, dependent variable, regressors and weights as this model.
- include_constant: bool =
False¶ Flag indicating whether to include the constant in the comparison. The default is False.
- sigmamore: bool =
False¶ Flag indicating whether to base both covariance estimates on the error variance estimated by this model, which is efficient under the null. Cannot be used with
sigmaless. The default is False.- sigmaless: bool =
False¶ Flag indicating whether to base both covariance estimates on the error variance estimated by
other. Cannot be used withsigmamore. The default is False.
- Returns:¶
A named tuple with the fields
statistic, which contains the test statistic, p-value, distribution and null as a WaldTestStatistic, andestimates, a DataFrame with the coefficients included in the test. An InvalidTestStatistic is returned as the statistic when the statistic is negative or not finite. The columns ofestimatesareb0(fromother),b1(from this model), their differenceb0-b1andStd. Err., the standard error of the difference. The standard error is NaN if the variance of the difference is negative.- Return type:¶
- Raises:¶
TypeError – If
otheris not a panel results object, or if either model was not estimated using the unadjusted covariance estimator.ValueError – If
sigmamoreandsigmalessare both True, if the models were not estimated using the same observations, dependent variable and weights, or if the models do not have any coefficients in common.
Notes
The test statistic is
\[H = (b_0 - b_1)^{\prime} (V_0 - V_1)^{-1} (b_0 - b_1)\]where \(b_0\) and \(V_0\) are the coefficients and covariance from
other, which is consistent under both the null and the alternative, and \(b_1\) and \(V_1\) are from this model, which is efficient under the null. The null hypothesis is that there is no systematic difference in the coefficients, which for a fixed effects model compared with a random effects model means that the effects are uncorrelated with the regressors. The statistic is asymptotically \(\chi^2_k\), where \(k\) is the number of coefficients compared.Only coefficients found in both models are compared. The constant is excluded unless
include_constantis True.The result is only meaningful when \(V_0 - V_1\) is positive definite, which is guaranteed in large samples if the null is true. If it is not, a warning is issued and a generalized inverse is used. If the resulting statistic is negative or not finite, the data do not satisfy the assumptions of the test and an InvalidTestStatistic is returned. This can happen, for example, if
otheris a pooled model, since the unadjusted covariance of a pooled model ignores the entity effects.Both models must use the default unadjusted covariance estimator. The statistic also requires that the models are estimated using the same observations, the same dependent variable and the same weights, which are checked. The regressors are not checked: only coefficients with the same name in both models are compared.
Effects that are included in
otherbut not in this model are not tested separately. For example, ifotherincludes time effects and this model does not, the null hypothesis is that the regressors are uncorrelated with the entity effects and with the time effects, and the test can reject because of the time effects. To test only the entity effects, include the time dummies as regressors in this model. Only the coefficients found in both models are compared, so the coefficients on the time dummies are not part of the test.References
Hausman, J. A. (1978). Specification tests in econometrics. Econometrica, 46(6), 1251-1271.
Examples
>>> from linearmodels import PanelOLS, RandomEffects >>> from linearmodels.datasets import wage_panel >>> data = wage_panel.load().set_index(["nr", "year"]) >>> y = data["lwage"] >>> x = data[["hours"]] >>> fe_res = PanelOLS(y, x, entity_effects=True).fit() >>> re_res = RandomEffects(y, x).fit() >>> results = re_res.hausman(fe_res) >>> print(results) Hausman specification test H0: No systematic difference in coefficients between models Statistic: ... P-value: ... Distributed: chi2(1) ...The statistic and the estimates can be unpacked.
>>> test, estimates = results