library(AER); library(stargazer) #restringir a salarios observados non-missing oursample <- subset(MROZ, !is.na(wage)) # primeiro estagio: forma reduzida stage1 <- lm(educ ~exper + I(exper^2)+ motheduc+fatheduc, data=oursample) #segundo estagio man.2SLS <- lm(log(wage) ~fitted(stage1)+exper+ I(exper^2), data=oursample) #2SLS automatico aut.2SLS <- ivreg(log(wage) ~ educ+exper+I(exper^2)|motheduc+fatheduc+exper+I(exper^2), data=oursample) # tabelas resultados stargazer(stage1,man.2SLS,aut.2SLS, type="text", keep.stat=c("n","rsq")) #motheduc como instrumento aut.2SLSmoth <- ivreg(log(wage) ~ educ+exper+I(exper^2)|motheduc+exper+I(exper^2), data=oursample) #fatheduc como instrumento aut.2SLSfath <- ivreg(log(wage) ~ educ+exper+I(exper^2)|fatheduc+exper+I(exper^2), data=oursample) #tabelas resultados stargazer(aut.2SLS, aut.2SLSmoth, aut.2SLSfath, iv, type="text", keep.stat=c("n","rsq"))