The ivlewbel Package. A new way to Tackle Endogenous Regressor Models.
This article is originally published at https://diffuseprior.wordpress.com
In April 2012, I wrote this blog post demonstrating an approach proposed in Lewbel (2012) that identifies endogenous regressor coefficients in a linear triangular system. Now I am happy to announce the release of the ivlewbel package, which contains a function through which Lewbel’s method can be applied in R. This package is now available to download on the CRAN.
Please see the example from the previous blog post replicated in the below. Additionally, it would be very helpful if people could comment on bugs and additional features they would like to add to the package. My contact details are in the about section of the blog.
library(ivlewbel) beta1 <- beta2 <- NULL for(k in 1:500){ #generate data (including intercept) x1 <- rnorm(1000,0,1) x2 <- rnorm(1000,0,1) u <- rnorm(1000,0,1) s1 <- rnorm(1000,0,1) s2 <- rnorm(1000,0,1) ov <- rnorm(1000,0,1) e1 <- u + exp(x1)*s1 + exp(x2)*s1 e2 <- u + exp(-x1)*s2 + exp(-x2)*s2 y1 <- 1 + x1 + x2 + ov + e2 y2 <- 1 + x1 + x2 + y1 + 2*ov + e1 x3 <- rep(1,1000) dat <- data.frame(y1,y2,x3,x1,x2) #record ols estimate beta1 <- c(beta1,coef(lm(y2~x1+x2+y1))[4]) #init values for iv-gmm beta2 <- c(beta2,lewbel(formula = y2 ~ y1 | x1 + x2 | x1 + x2, data = dat)$coef.est[1,1]) } library(sm) d <- data.frame(rbind(cbind(beta1,"OLS"),cbind(beta2,"IV-GMM"))) d$beta1 <- as.numeric(as.character(d$beta1)) sm.density.compare(d$beta1, d$V2,xlab=("Endogenous Coefficient")) title("Lewbel and OLS Estimates") legend("topright", levels(d$V2),lty=c(1,2,3),col=c(2,3,4),bty="n") abline(v=1)
Thanks for visiting r-craft.org
This article is originally published at https://diffuseprior.wordpress.com
Please visit source website for post related comments.