Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case of negative model_ss for IV2SLS #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Handle case of negative model_ss for IV2SLS
  • Loading branch information
jsr-p committed Feb 8, 2024
commit 1746391774b0c3924a76c81cafd8a827fe67aa74
15 changes: 13 additions & 2 deletions stargazer/translators/linearmodels.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
Compatibility layer with results from linearmodels.
"""

from math import sqrt
from math import nan, sqrt

from linearmodels.iv.results import IVResults, OLSResults
from linearmodels.panel.results import (
@@ -39,6 +39,17 @@
linear_model_map_iv = dict()


def handle_resid_std_err(model):
if isinstance(model, IVResults):
try:
resid_std_err = sqrt(model.model_ss / model.df_resid)
except ValueError: # Negative model_ss IV
resid_std_err = nan
else:
resid_std_err = sqrt(model.model_ss / model.df_resid)
return resid_std_err


def extract_model_data(model):
data = {}
if isinstance(model, (PanelEffectsResults, RandomEffectsResults, PanelResults)):
@@ -62,7 +73,7 @@ def extract_model_data(model):
data["cov_names"] = model.params.index.values
data["conf_int_low_values"] = model.conf_int().lower
data["conf_int_high_values"] = model.conf_int().upper
data["resid_std_err"] = sqrt(model.model_ss / model.df_resid)
data["resid_std_err"] = handle_resid_std_err(model)
data["f_statistic"] = model.f_statistic.stat
data["f_p_value"] = model.f_statistic.pval
data["r2_adj"] = None