analyze_hausman_test

source

analyze_hausman_test(df, dv, idvs, *, entity=None, time=None)

Run the Hausman test comparing fixed-effects and random-effects estimates.

Parameters

Name Type Description Default
df pd.DataFrame Long panel data frame. required
dv str Dependent variable name. required
idvs Sequence[str] | str Independent variable name(s). required
entity str | None The cross-section and time identifiers. Default to the panel declared via :func:expdpy.set_panel / :func:expdpy.set_labels (set_panel=True). None
time str | None The cross-section and time identifiers. Default to the panel declared via :func:expdpy.set_panel / :func:expdpy.set_labels (set_panel=True). None

Returns

Name Type Description
HausmanTestResult The test statistic, degrees of freedom, p-value and the compared coefficients.

Examples

Basic — compare the FE and RE estimates. With the panel declared by set_panel=True, entity and time are resolved automatically.

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ht = ex.analyze_hausman_test(df, dv="gini_regional", idvs=["log_gdp_pc"])
ht.statistic, ht.df_test, ht.p_value
(13.65930971955897, 1, 0.00021915204898468124)

Advanced — several regressors, then read the compared coefficients side by side.

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ht = ex.analyze_hausman_test(
    df, dv="gini_regional", idvs=["log_gdp_pc", "trade_share"]
)
ht.fe_coefs         # fixed-effects estimates
ht.re_coefs         # random-effects estimates
print(ht.interpret())
Hausman test (χ²(2) = 14.400, p = 0.0007468): **reject** the null — the random-effects assumption is violated, so prefer **fixed effects**. Note that failing to reject reflects a lack of evidence against random effects, not proof that it is correct.