StatsReporting / stargazer

Python implementation of the R stargazer multiple regression model creation tool
Other
195 stars 48 forks source link

Is it possible to use statsmodels time series models with this package ? #96

Closed elemn closed 1 year ago

elemn commented 1 year ago

Hello,

I am attempting to export the results of an ARDL model I calculated with statsmodels, but I get the impression that the package only supports OLS (no ARDL, ARIMA). Is there a makeshift way to get this working? Right now, running :

Stargazer([model_fit])

returns "ValueError: Please use trained OLS models as inputs".

The actual model output should be very similar to OLS.

toobaz commented 1 year ago

Hi @elemn . While the message of the ValueError is definitely misleading, it seems to me that stargazer supports ARDL just fine. At least, the following code, combining an ARDL and an OLS, doesn't raise any error for me, and outputs a table (in jupyter):

from statsmodels.tsa.api import ARDL
from statsmodels.api import OLS
from statsmodels.datasets import danish_data
from stargazer.stargazer import Stargazer

data = danish_data.load_pandas().data
lrm = data.lrm
exog = data[["lry", "ibo", "ide"]]

m = ARDL(data.lrm, 3, data[["lry", "ibo", "ide"]], 3).fit()
est = OLS.from_formula('lrm ~ lry + ibo + ide', data=data).fit()

table = Stargazer([m, est])
table
toobaz commented 1 year ago

Sorry, I should have mentioned that the above works with current master. I confirm that the error you report does rise with the last version on pypi, 0.0.5.

I will upload a new version, hopefully before the end of July.

elemn commented 1 year ago

Hello @toobaz , thank you very much for your response! If possible, would you be able to post back here once that master is uploaded? It would very much be appreciated.

toobaz commented 1 year ago

Hello @elemn , stargazer 0.0.6 was just uploaded to pypi!

alistaircameron commented 10 months ago

Hello,

I am having the same issue as the OP, but with PanelOLS from linearmodels. Specifically, updating linearmodels and stargazer to the current versions, then running the PanelOLS example in examples.ipynb from stargazer's documentation returns "ValueError: Please use trained OLS models as inputs". 

Many thanks for your work, it's a great package!

toobaz commented 10 months ago

I am having the same issue as the OP, but with PanelOLS from linearmodels

Hi @alistaircameron , see https://github.com/StatsReporting/stargazer/pull/98 : support PanelOLS was just merged and will be included in next release, I guess in the next month or so. If you are in a hurry, you can use the git version for now.