R:使用仪器变量和交互项的Logit回归

时间:2015-04-19 13:46:16

标签: r logistic-regression interaction

我对R有一个严重的问题。我没有弄清楚如何使用仪器变量运行logit回归。 棘手的是我有2个独立变量作为交互项,但是仪器仅适用于两个独立变量中的一个。此外,我有几个控件。 我尝试了AER ivreg包的一些东西,但我无法弄清楚我必须在回归命令中键入什么。

如果有人能帮助我,我将非常感激。

1 个答案:

答案 0 :(得分:0)

我认为这篇文章是你需要的: http://www.r-bloggers.com/a-simple-instrumental-variables-problem/

帖子中的代码

library(AER)
library(lmtest)
data("CollegeDistance")
cd.d<-CollegeDistance
simple.ed.1s<- lm(education ~ distance,data=cd.d)
cd.d$ed.pred<- predict(simple.ed.1s)
simple.ed.2s<- lm(wage ~ urban + gender + ethnicity + unemp + ed.pred ,     data=cd.d)
simple.comp<- encomptest(wage ~ urban + gender + ethnicity + unemp + ed.pred , wage ~ urban + gender + ethnicity + unemp + education , data=cd.d)
1s.ftest<- encomptest(education ~ tuition + gender + ethnicity + urban ,     education ~ distance , data=cd.d)

library(arm)
coefplot(lm(wage ~ urban + gender + ethnicity + unemp + education,data=cd.d),vertical=FALSE,var.las=1,varnames=c("Education","Unemp","Hispanic","Af-am","Female","Urban","Education"))
coefplot(simple.ed.2s ,     vertical=FALSE,var.las=1,varnames=c("Education","Unemp","Hispanic","Af-am","Female","Urban","Education"))