# Tobit or Censored Regression Model # Three methods : Heckman 2 step procedure, MLE, Powell's median (quantile) estimator # For the MLE, need "survival" package # For the Powell estimator, need "quantreg" package # 0. Data generation n <- 500 x1 <- rnorm(n,sd=3) x2 <- runif(n,min=-2,max=2) ys <- 1 + x1 - x2 + rt(n,df=8) c <- (ys > 0) y <- pmax(ys,0) # 1. Heckman 2 step estimator probit <- glm(c~x1+x2,family=binomial(link="probit")) lambda <- dnorm(cbind(1,x1,x2)%*%(probit$coef))/pnorm(cbind(1,x1,x2)%*%(probit$coef)) hfit <- lm(y ~ x1 + x2 + lambda) # 2. MLE tfit <- survreg(Surv(y, c, type='left') ~ x1 + x2, dist='gaussian') predict(tfit,type="response") # 3. Powell estimator require(quantreg) pfit <- rq.fit.fcen(cbind(1,x1,x2),y,1-c,left=TRUE) pfit$coef