如何使用 statsmodels python 进行 2SLS IV 回归? [英] How to do 2SLS IV regression using statsmodels python?
问题描述
我正在尝试使用 statsmodels 库在 python 中进行两阶段最小二乘回归.
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
是我的内生变量,我的工具是 Diabetes
,我的因变量是 Log Income
.
Reads Nutri
is my endogenous variable my instrument is Diabetes
and my dependent variable is Log Income
.
我这样做对吗?它与我在 stata 上做的方式大不相同.
Did I do this right? its much different than the way I would do it on stata.
此外,当我执行 resultIV.summary() 时,我收到一个类型错误,这与 F 统计数据为 nonetype 有关系,我该如何重新喜欢这个?
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?
非常感谢任何帮助.
推荐答案
当我想自己做一个 IV2SLS 回归并遇到同样的问题时,我发现了这个问题.所以,只为所有来到这里的其他人.
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.
统计模型文档显示如何使用这个命令.您的参数是 endog
、exog
和 instrument
,其中 exog
包括检测的变量和 instrument
工具和其他控制变量.从这个意义上说,你的模型很好.
The documentation of statsmodels shows how to use this command. Your arguments are endog
, exog
, and instrument
in that order where exog
includes variables which are instrumented and instrument
the instruments and other control variables. In that sense, your model is fine.
您发现的 TypeError
当前是一个开放错误 在 0.6.0 和 0.8.1 版本中.并将根据里程碑在 0.9.0 中修复.
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.
更新 (28.06.2018):9.0.0 版已于 5 月 15 日发布,应包含对上述错误的修复.
Update (28.06.2018): Version 9.0.0 was released on 15 May and should include a fix for the aforementioned bug.
这篇关于如何使用 statsmodels python 进行 2SLS IV 回归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!