NextStatNextStat

Econometrics & Causal Inference

NextStat includes panel data estimators, difference-in-differences, instrumental variables, and doubly-robust causal inference — all with formula interfaces and robust standard errors.

Panel Fixed Effects

from nextstat.econometrics import panel_fe_fit, panel_fe_from_formula

fit = panel_fe_fit(X, y, entity_ids, cluster_ids=entity_ids)
# or
fit = panel_fe_from_formula("y ~ x1 + x2", data, entity_col="firm", cluster_col="firm")

Difference-in-Differences

from nextstat.econometrics import did_twfe_fit, event_study_twfe_fit

# Two-Way Fixed Effects DiD
fit = did_twfe_fit(y, treated, post, entity_ids, time_ids)

# Event study with leads and lags
fit = event_study_twfe_fit(
    y, treated, event_time, entity_ids, time_ids,
    leads=3, lags=5
)

Instrumental Variables (2SLS)

from nextstat.econometrics import iv_2sls_fit, iv_2sls_from_formula

fit = iv_2sls_fit(y, X_endog, X_exog, Z_instruments, cov_type="hc1")

# Formula interface
fit = iv_2sls_from_formula(
    "wage ~ education | parent_education + distance_to_college",
    data, cov_type="cluster", cluster_col="state"
)

# Weak-IV diagnostics
print(fit.first_stage_f)     # first-stage F statistic
print(fit.partial_r2)        # partial R² of instruments

Doubly-Robust Causal Inference (AIPW)

from nextstat.causal import aipw

result = aipw.estimate(y, treatment, X)

print(result.ate)        # Average Treatment Effect
print(result.att)        # Average Treatment on Treated
print(result.e_value)    # E-value for sensitivity analysis

Propensity Scores

from nextstat.causal import propensity

ps = propensity.fit(treatment, X)

print(ps.scores)              # propensity scores
print(ps.ipw_weights)         # inverse probability weights
print(ps.overlap_diagnostic)  # overlap statistics
print(ps.balance_table)       # covariate balance before/after