# # #R Code for estimating ZIOP and ZIOPC models # #BEB 4/27/2011 # # # #clear memory rm( list=ls() ) #load two necessary packages library(mvtnorm) library(MASS) #set the seed set.seed(2) ################################################################## ###########Create a dataset for use in the models below########### ################################################################## #set the number of observations n<-1000 #define true gammas and betas G<-rbind(1, -0.25, -1) G<-as.matrix(G) cutpoints<-rbind(-100, 0, 4.5, 5.5, 100) B<-rbind(1,1) B<-as.matrix(B) #create some covariates x0<-matrix(rep(1,n)) x1<-matrix(log(runif(n, min=0, max=100)),n,1) x2star<-matrix(runif(n, min=0, max=1), n, 1) x2<-ifelse(x2star>.25,1,0) Z<-cbind(x0,x1,x2) Z<-as.matrix(Z) X<-cbind(x1,x2) X<-as.matrix(X) #create a zero inflated dependent variable that #ranges from 0 to 3, with no correlated disturbances phi<-pnorm(Z%*%G) vcv<-matrix(c(1,0,0,1), nrow=2, ncol=2) e<-mvrnorm(n, mu=c(0,0), Sigma=vcv) ystar<-X%*%B+e[,1] y<-matrix(0,n,1) for(i in 2:4){y[ystar>cutpoints[i]]<-y[ystar>cutpoints[i]]+1} yzero<-matrix(0,n,1) error<--1*e[,2] flag<-error