I am trying to save as PNG File the summary of some regressions that I am doing using the package linearmodels
from linearmodels.iv import IV2SLS
[...]
modelIV =IV2SLS.from_formula(formulaIV,Data).fit(cov_type='unadjusted')
print(modelIV.summary)
I tried to do this, but it is not working:
plt.rc('figure', figsize=(12, 7))
plt.text(0.01, 0.05, str(modelIV.summary()), {'fontsize': 10}, fontproperties = 'monospace')
plt.axis('off')
plt.tight_layout()
plt.savefig('iv_model.png')
Can you help me to figure out what is wrong? Thanks in advance!
CodePudding user response:
Do not know why but this is working:
plt.rc('figure', figsize=(12, 7))
plt.text(0.01, 0.05, modelIV, {'fontsize': 10}, fontproperties = 'monospace')
plt.axis('off')
plt.tight_layout()
plt.savefig('iv_logit.png')
CodePudding user response:
summary
is a property and so should not be called.
from statsmodels.api import add_constant
from linearmodels.datasets import wage
from linearmodels import IV2SLS
import matplotlib.pyplot as plt
men = wage.load()
men = men[["educ", "wage", "sibs", "exper"]]
men = add_constant(men)
men = men.dropna()
res_first = IV2SLS(men.educ, men[["const", "sibs"]], None, None).fit(
cov_type="unadjusted"
)
plt.rc("figure", figsize=(12, 7))
plt.text(
0.01, 0.05, str(res_first.summary), {"fontsize": 10}, fontproperties="monospace"
)
plt.axis("off")
plt.tight_layout()
plt.gcf().tight_layout(pad=1.0)
plt.savefig("iv_model.png", transparent=False)
produces