# This is a Monte Carlo for the Tobit Example in slides # *************** Before the loop ********************* set seed 547 nulldata 1500 #****** Loop ********** loop 500 --progressive --quiet # generate variables genr u = uniform() genr kids = (u>0.25)+(u>0.75) genr educ=8*(u<=.15)+12*(u>.15)*(u<=.6)+16*(u>.6)*(u<=.9)+21*(u>.9) genr h_star = 5 + 0.5*educ - 5*kids + 7*normal() genr h=(h_star>0)*h_star # estimate with different models ols h const educ kids scalar ols_b0=$coeff(const) scalar ols_be=$coeff(educ) scalar ols_bk=$coeff(kids) smpl h>0 --restrict ols h const educ kids scalar ols_subsmpl_b0=$coeff(const) scalar ols_subsmpl_be=$coeff(educ) scalar ols_subsmpl_bk=$coeff(kids) smpl full tobit h const educ kids scalar tobit_b0=$coeff(const) scalar tobit_be=$coeff(educ) scalar tobit_bk=$coeff(kids) genr beta = $coeff # estimate the marginal effect of an extra child genr kids1=kids+1 matrix x0={const,educ,kids} matrix x1={const,educ,kids1} series h0=(x0*beta>0)*x0*beta series h1=(x1*beta>0)*x1*beta series Mg_kid=h1-h0 scalar Mg_kid1=mean(Mg_kid) # saving results store tobit.gdt ols_b0 ols_be ols_bk ols_subsmpl_b0 ols_subsmpl_be ols_subsmpl_bk tobit_b0 tobit_be tobit_bk Mg_kid1 endloop # Sample from the last loop freq kids freq educ gnuplot h h_star --suppress-fitted --output=display { set title 'Censoring'; set ylabel 'Observed hours'; set xlabel 'Desired hours';} # model in minutes: the coefficients are the same than the one in hours, the loglikelihood changes tobit h const educ kids genr beta60 =60*$coeff genr h2=60*h tobit h2 const educ kids beta60 summary Mg_kid --by=educ --simple #************ Expectation estimates ********** open tobit.gdt summary ols* --simple summary tobit* --simple summary Mg_kid1 #************* interval regression example (from gretl manual) nulldata 100 # generate artificial data set seed 201449 x = normal() epsilon = 0.2*normal() ystar = 1 + x + epsilon lo_bound = floor(ystar) hi_bound = ceil(ystar) # run the interval model intreg lo_bound hi_bound const x quit