analyze_cre_table

source

analyze_cre_table(
    df,
    dv,
    idvs,
    *,
    entity=None,
    time=None,
    cov_type='clustered',
    cluster_entity=True,
    format='gt',
)

Estimate a Correlated Random Effects (Mundlak) model.

Augments a random-effects model with the entity means of each time-varying regressor. By the Mundlak equivalence the coefficient on each original regressor equals its within (fixed-effects) estimate — so analyze_cre_table(df, "y", "x", ...) recovers the same slope on x as analyze_regression_table(df, "y", "x", feffects=[entity]) — while the coefficient on x_mean measures the between-vs-within gap. A joint Wald test that all *_mean coefficients are zero is the regression-form Hausman test (reported on the fitted model as _cre_mundlak_stat / _cre_mundlak_df / _cre_mundlak_p).

Parameters

Name Type Description Default
df pd.DataFrame Long panel data frame. required
dv str Dependent variable name. required
idvs Sequence[str] | str Time-varying independent variable name(s). required
entity str | None The cross-section and time identifiers. Both default to the declared panel (set via :func:~expdpy.set_panel), so they can be omitted when it is declared. None
time str | None The cross-section and time identifiers. Both default to the declared panel (set via :func:~expdpy.set_panel), so they can be omitted when it is declared. None
cov_type Literal['clustered', 'robust', 'unadjusted'] Covariance estimator: "clustered" (default), "robust" or "unadjusted". 'clustered'
cluster_entity bool Cluster by entity when cov_type="clustered". True
format Literal['gt', 'md', 'df', 'html'] Output format for the rendered table. 'gt'

Returns

Name Type Description
CRETableResult models (the fitted linearmodels result), etable (the rendered table) and df (tidy coefficients for each regressor, its *_mean and the intercept).

Examples

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)
cre = ex.analyze_cre_table(df, dv="gini_regional", idvs=["log_gdp_pc"])
cre.etable          # the log_gdp_pc coefficient == the within / fixed-effects estimate
cre.df              # rows for log_gdp_pc, log_gdp_pc_mean and Intercept
print(cre.interpret())
This Correlated Random Effects (Mundlak) model relates **gini_regional** to its regressors *and* their unit (entity) means. By the Mundlak equivalence the coefficient on each original regressor equals its **within (fixed-effects)** estimate, while the coefficient on the mean is the gap between the between- and within-unit associations.

- **log_gdp_pc** (within estimate): a one-unit increase is associated with gini_regional that is 0.0292 higher (not statistically significant at conventional levels).

Joint test that the 1 mean coefficient(s) are zero — the regression-form Hausman test — χ²(1) = 2.23, p = 0.136: this are indistinguishable from zero, so **random effects is admissible** (and more efficient than fixed effects).

_These are associations, not causal effects. A causal reading needs a research design — see `explain('correlation_vs_causation')`._