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

Support for pyfixest #105

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion stargazer/stargazer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def extract_data(self):
for use or modification. They should not be able to
be modified by any rendering parameters.
"""

self.model_data = []
for m in self.models:
self.model_data.append(self.extract_model_data(m))
Expand Down Expand Up @@ -344,7 +345,7 @@ class Renderer:
def __init__(self, table, **kwargs):
"""
Initialize a new renderer.

"table": Stargazer object to render
"""

Expand Down
7 changes: 7 additions & 0 deletions stargazer/translators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ def register_class(klass, extractor):
except ModuleNotFoundError:
# linearmodels not found
pass

### PYFIXEST ###
try:
from .pyfixest import classes
except ModuleNotFoundError:
# pyfixest not found
pass
52 changes: 52 additions & 0 deletions stargazer/translators/pyfixest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Compatibility layer with results from pyfixest.
"""

from ..starlib import _extract_feature

from . import register_class
from pyfixest.estimation.feols_ import Feols
from pyfixest.estimation.feiv_ import Feiv
from pyfixest.estimation.fepois_ import Fepois

# For features that are simple attributes of "model", establish the
# mapping with internal name:

pyfixest_map = {
'r2' : '_r2',
'cov_names' : '_coefnames',
'nobs' : '_N',
}

def extract_model_data(model):

data = {}
for key, val in pyfixest_map.items():
data[key] = _extract_feature(model, val)

data['dependent_variable'] = model._fml.split("~")[0].replace(" ", "")
data['cov_values'] = model.coef()
data['cov_std_err'] = model.se()
data['p_values'] = model.pvalue()
data['conf_int_low_values'] = model.confint().iloc[:,0]
data['conf_int_high_values'] = model.confint().iloc[:,1]


data['resid_std_err'] = None
data['degree_freedom_resid'] = None
data["f_statistic"] = None
data["f_p_value"] = None
data["r2_adj"] = None
data["pseudo_r2"] = None

return data


classes = [(Feols, extract_model_data),
(Fepois, extract_model_data),
(Feiv, extract_model_data)
]

for klass, translator in classes:
register_class(klass, translator)