analyze_estimation

source

analyze_estimation(
    df,
    dv,
    idvs=None,
    *,
    feffects=None,
    stepwise=None,
    vcov=None,
    cluster=None,
    time_id=None,
    panel_id=None,
    lag=None,
    weights=None,
    ssc=None,
    format='gt',
)

Estimate an OLS model, optionally several nested or multi-outcome models at once.

A richer companion to :func:expdpy.analyze_regression_table: same OLS/fixed-effects core, but with stepwise nested-model comparison, serial-correlation-robust standard errors (Newey-West / Driscoll-Kraay), multiple outcomes and weights.

Parameters

Name Type Description Default
df pd.DataFrame Data frame containing the variables. required
dv Sequence[str] | str Dependent-variable name, or several names to estimate the same right-hand side for each outcome side by side. required
idvs Sequence[str] | str | None Independent regressor name(s). None
feffects Sequence[str] | str | None Fixed-effect variable name(s) absorbed during estimation. None
stepwise Stepwise | None Wrap idvs in a stepwise sequence — "sw"/"sw0" (separate) or "csw"/"csw0" (cumulative) — to estimate nested models in one call and read them side by side (great for “watch the estimate move as I add controls”). None
vcov str | Mapping[str, str] | VCovSpec | None Standard-error type: "iid", "hetero"/"HC1" ("HC2"/"HC3" without fixed effects), "CRV1"/"CRV3" (cluster-robust, with cluster=), "NW"/"DK" (serial-correlation robust, with time_id=/panel_id=), a pyfixest-style {"CRV1": "firm"} mapping, or a :class:VCovSpec. Defaults to clustered SEs when cluster is given, else "iid". None
cluster Sequence[str] | str | None Cluster variable name(s) — a shortcut that selects "CRV1" standard errors. None
time_id str | None Required for vcov="NW"/"DK" (the time and panel identifiers, optional lag). None
panel_id str | None Required for vcov="NW"/"DK" (the time and panel identifiers, optional lag). None
lag str | None Required for vcov="NW"/"DK" (the time and panel identifiers, optional lag). None
weights str | None Optional weights column name. None
ssc Any | None Small-sample-correction object (defaults to the Stata-reghdfe-consistent one). None
format Literal['gt', 'tex', 'md', 'df', 'html'] Output format for the rendered etable. 'gt'

Returns

Name Type Description
EstimationResult models, etable, df (tidy coefficients), model_kind, fit_stats and notes. Use .interpret() / .explain() for plain-language output.

Examples

Basic — a single OLS regression with heteroskedastic standard errors:

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)
ex.analyze_estimation(
    df,
    dv="gini_regional",
    idvs=["log_gdp_pc", "log_gdp_pc_sq"],
    vcov="hetero",
).etable
Regional inequality (Gini)
(1)
coef
Log GDP per capita -0.155***
(0.040)
Log GDP per capita² 0.008***
(0.002)
Intercept 0.991***
(0.181)
stats
Observations 880
R2 0.043
Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell: Coefficient (Std. Error)

Advanced — a cumulative-stepwise comparison with heteroskedastic SEs:

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)
res = ex.analyze_estimation(
    df,
    dv="gini_regional",
    idvs=["log_gdp_pc", "log_gdp_pc_sq", "log_gdp_pc_cu"],
    stepwise="csw",
    vcov="hetero",
)
res.etable          # three nested models side by side
res.fit_stats       # N and R² per model
print(res.interpret())
This OLS model relates **gini_regional** to its regressors.

- **log_gdp_pc**: each one-unit increase is associated with gini_regional that is 0.00537 lower (statistically significant at the 5% level).

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