regression

regression(
    data,
    y,
    x,
    year=None,
    *,
    fixed_effects=None,
    cluster=None,
    robust=True,
    title=None,
    ref=None,
)

Ordinary least squares, with several specifications side by side.

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 (one model), or a list of lists (one model per list, e.g. adding controls step by step) required
year The year to use (default: the last with data for y and every regressor), a list of years, or "all" to pool every year None
fixed_effects A column, a coarser scale (e.g. the scale above the units’), "year", or a list of them: absorbed as dummies and reported as Yes/No rows instead of coefficients. A list with one entry per model, where an entry is None or a list, sets them model by model None
cluster str | None A column or a coarser scale: standard errors clustered by it (p-values and intervals then use a t distribution with one degree of freedom less than clusters) None
robust bool Heteroskedasticity-robust standard errors (HC1) when there is no cluster; False: classical standard errors True
title str | None The title of the table and of the figure None

Returns

Name Type Description
RegressionResult A result with .gt (the regression table: coefficients with stars, standard errors in parentheses, the fixed effects, N and R²), .fig (the coefficients with 95% confidence intervals across models), .df (tidy: model, term, estimate, std_error, statistic, p_value, conf_low, conf_high), .summary (one row per model: n, r2, r2_adj, fixed_effects, std_errors), .models (the fitted statsmodels results) and .interpret().

Example

!pip install -q geo4bolivia
import geo4bolivia as geo

res = geo.regression("sdg", "index_sdg",
                     [["urbanization"], ["urbanization", "population"]],
                     fixed_effects=[None, "department"])
print(res.interpret())
res.gt

Ordinary least squares of Sustainable Development Index, IDS (0-100), 2024: 2 specifications side by side. Model (2), the last one, reads as follows.

  • Urbanization rate (% of population): a one-unit higher value goes with Sustainable Development Index, IDS (0-100) that is 0.0869 higher (statistically significant at the 1% level; 95% interval 0.0715 to 0.102), the other regressors held constant, within the same department.
  • Population (census): a one-unit higher value goes with Sustainable Development Index, IDS (0-100) that is 7.05e-06 higher (statistically significant at the 1% level; 95% interval 2.7e-06 to 1.14e-05), the other regressors held constant, within the same department.

Fixed effects for Department absorb every difference between their groups, so the coefficients compare observations of the same group only. The model has 343 observations and R² = 0.449 (adjusted 0.432): the regressors and the fixed effects account for 44.9% of the variation in Sustainable Development Index, IDS (0-100). Standard errors are heteroskedasticity-robust (HC1).

Across the models, the coefficient on Urbanization rate (% of population) is (1) 0.094, (2) 0.0869. It is stable: a coefficient that moves when regressors or fixed effects are added was partly picking up what they measure; one that stays put does not depend on them.

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

Regression of Sustainable Development Index, IDS (0-100)
Ordinary least squares, 2024
Sustainable Development Index, IDS (0-100)
(1) (2)
Urbanization rate (% of population) 0.094*** 0.087***
(0.008) (0.008)
Population (census) 7.05e-06***
(2.22e-06)
Intercept 57.582***
(0.313)
Department fixed effects No Yes
Observations 343 343
R² 0.313 0.449
Adjusted R² 0.311 0.432
*** p<0.01, ** p<0.05, * p<0.10. Standard errors in parentheses: heteroskedasticity-robust (HC1).