How to do 2SLS IV regression using statsmodels python?

孤者浪人 提交于 2020-02-22 08:45:25

问题


I'm trying to do 2 stage least squares regression in python using the statsmodels library.

from statsmodels.sandbox.regression.gmm import IV2SLS                       
resultIV = IV2SLS(dietdummy['Log Income'], dietdummy.drop(['Log Income', 'Diabetes']),     
dietdummy.drop(['Log Income', 'Reads Nutri')

Reads Nutri is my endogenous variable my instrument is Diabetes and my dependent variable is Log Income.

Did I do this right? its much different than the way I would do it on stata.

Also, when I do resultIV.summary() I get a type error, something to do with the F statistic being nonetype, how can i reslove this?

Any help is greatly appreciated.


回答1:


I found this question when I wanted to do an IV2SLS regression myself and had the same problem. So, just for everybody else who landed here.

The documentation of statsmodels shows how to use this command. Your arguments are endog, exog, and instrumentin that order where exog includes variables which are instrumented and instrument the instruments and other control variables. In that sense, your model is fine.

The TypeError you found is currently an open bug in versions 0.6.0 and 0.8.1. and will be fixed in 0.9.0 according to the milestone.

Update (28.06.2018): Version 9.0.0 was released on 15 May and should include a fix for the aforementioned bug.



来源:https://stackoverflow.com/questions/37012110/how-to-do-2sls-iv-regression-using-statsmodels-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!