panel_model

panel_model(
    data,
    y,
    x,
    *,
    models=('pooled', 'between', 'fe', 're'),
    time_effects=False,
    cluster=True,
    title=None,
    ref=None,
)

The standard panel estimators side by side, and the Hausman test of fixed against random effects.

The units are geo_id and the periods year; every year with data is used.

Parameters

Name Type Description Default
data A dataset id, or a panel with geo_id and year, e.g. from load or combine required
y str The outcome column required
x The regressors: a column or a list of columns required
models The estimators to compare, in order: "pooled" (least squares on all rows), "between" (on the units’ averages over the years), "fe" (fixed effects: each unit’s deviations from its own average) and "re" (random effects) ('pooled', 'between', 'fe', 're')
time_effects bool Add year effects (to every estimator but "between") False
cluster bool Standard errors clustered by unit; False: heteroskedasticity-robust. The between estimator, with one row per unit, is always heteroskedasticity-robust True
title str | None The title of the table and of the figure None

Returns

Name Type Description
PanelModelResult A result with .gt (the comparison table), .fig (the coefficients with 95% confidence intervals across estimators), .df (tidy: model, term, estimate, std_error, statistic, p_value, conf_low, conf_high), .summary (one row per model: n, units, years, r2, r2_within, r2_between, r2_overall), .models (the fitted linearmodels results, keyed by estimator), .hausman (statistic, df, p_value; None unless both "fe" and "re" are estimated and the test can be computed) and .interpret(). The Hausman test compares the fixed- and random-effects coefficients of the regressors with classical covariance matrices that share the residual variance of the fixed-effects model, so that their difference is positive semi-definite. Needs the linearmodels library (the [panel] extra).

Example

!pip install -q "geo4bolivia[panel]"
import geo4bolivia as geo

panel = geo.combine(["ntl", "pop"], scale="municipality")
res = geo.panel_model(panel, "ln_NTLpc", "pop_density")
print(res.interpret())
res.gt

Panel models of Log night-time lights per capita: 2,930 observations of 331 units over 9 years (2012–2020), estimated as pooled OLS, between, fixed effects, random effects.

  • Population density (people per km²), a one-unit higher value goes with Log night-time lights per capita that is:
    • 0.00117 higher pooling all rows (statistically significant at the 1% level);
    • 0.00121 higher between units (comparing the units’ averages over the years) (statistically significant at the 1% level);
    • 0.00217 higher within units (fixed effects: each unit compared with itself over the years) (statistically significant at the 1% level);
    • 0.0014 higher with random effects (a weighted mix of the between and within comparisons) (statistically significant at the 1% level).

The between estimate asks whether units with a higher regressor have a higher or lower outcome than other units; the within (fixed-effects) estimate asks whether a unit’s outcome moves when its own regressor moves, which leaves out every lasting difference between units. When the two disagree, the units that differ in the regressor also differ in other lasting ways that go with the outcome.

Hausman test: χ²(1) = 2.34, p = 0.126. The fixed- and random-effects estimates do not differ by more than chance allows, so random effects, the more precise of the two, are admissible. This is a lack of evidence against them, not a proof that they are right.

  • Note: Units with data in a single year (1 of 331) do not inform the fixed-effects estimates

These are associations, not causal effects. A causal reading needs a research design.

Panel models of Log night-time lights per capita
2,930 observations of 331 units, 2012–2020 (9 years)
Log night-time lights per capita
Pooled OLS Between Fixed effects Random effects
Population density (people per km²) 0.001*** 0.001*** 0.002*** 0.001***
(2.24e-04) (2.33e-04) (5.87e-04) (3.08e-04)
Intercept 13.518*** 13.472*** 13.464***
(0.067) (0.071) (0.070)
Unit effects No No Fixed Random
Year effects No No No No
Observations 2,930 331 2,930 2,930
Units 331 331 331 331
R² 0.047 0.052 0.006 0.004
R² within 0.005 0.005 0.006 0.005
R² between 0.051 0.052 0.018 0.051
*** p<0.01, ** p<0.05, * p<0.10. Standard errors in parentheses: clustered by geo_id (between: heteroskedasticity-robust).
Hausman test of fixed against random effects: χ²(1) = 2.34, p = 0.1258