version 10.0 capture log close *---------------------------- * Probit *---------------------------- log using chap16, replace * examine data use transport, clear summarize * probit probit auto dtime * marginal effects mfx mfx,at (dtime=20) mfx,at (dtime=30) * direct calculation nlcom (normalden(_b[_cons]+_b[dtime]*20)*_b[dtime] ) nlcom (normal(_b[_cons]+_b[dtime]*30) ) *---------------------------- * Multinomial logit *---------------------------- use nels_small, clear * summarize data summarize grades, detail tab psechoice * estimate model mlogit psechoice grades, baseoutcome(1) * compute predictions and summarize predict ProbNo ProbCC ProbColl summarize ProbNo ProbCC ProbColl * mfx compute mfx, predict(outcome(1)) at (6.64) mfx, predict(outcome(2)) at (6.64) mfx, predict(outcome(3)) at (6.64) mfx, predict(outcome(1)) at (2.635) mfx, predict(outcome(2)) at (2.635) mfx, predict(outcome(3)) at (2.635) *---------------------------- * Conditional logit *---------------------------- use cola, clear * summarize data summarize * view some observations list in 1/9 * generate alternative specific variables generate alt = mod(_n,3) generate pepsi = (alt==1) generate sevenup = (alt==2) generate coke = (alt==0) * view some observations list in 1/9 * summarize by alternative summarize choice price feature display if alt==1 summarize choice price feature display if alt==2 summarize choice price feature display if alt==0 * estimate the model clogit choice price pepsi sevenup,group(id) predict phat, pc1 #delimit ; /* Predicted probability pepsi --No display or features */ nlcom( exp(_b[pepsi]+_b[price]*1.00)/ (exp(_b[pepsi]+_b[price]*1.00) +exp(_b[sevenup]+_b[price]*1.25) +exp(_b[price]*1.10)) ); /* Predicted probability pepsi at 10 percent higher--No display or features */ nlcom( exp(_b[pepsi]+_b[price]*1.10)/ (exp(_b[pepsi]+_b[price]*1.10) +exp(_b[sevenup]+_b[price]*1.25) +exp(_b[price]*1.10)) ); /* Price Change in price of .15 coke on probability of pepsi */ nlcom( exp(_b[pepsi]+_b[price]*1.00)/ (exp(_b[pepsi]+_b[price]*1.00) + exp(_b[sevenup]+_b[price]*1.25) + exp(_b[price]*1.25)) - exp(_b[pepsi]+_b[price]*1.00)/ (exp(_b[pepsi]+_b[price]*1.00) +exp(_b[sevenup]+_b[price]*1.25) +exp(_b[price]*1.10)) ); #delimit cr * label values label define brandlabel 0 "Coke" 1 "Pepsi" 2 "SevenUp" label values alt brandlabel * estimate model asclogit choice price, case(id) alternatives(alt) basealternative(Coke) * post-estimation estat alternatives estat mfx estat mfx, at(Coke:price=1.10 Pepsi:price=1 SevenUp:price=1.25) *---------------------------- * Ordered probit *---------------------------- use nels_small, clear * summarize data summarize grades, detail tab psechoice * estimate model oprobit psechoice grades mfx, at(grades=6.64) predict(outcome(3)) mfx, at(grades=2.635) predict(outcome(3)) *---------------------------- * Poisson Regression *---------------------------- use olympics, clear keep if year==88 keep medaltot pop gdp summarize * summarize pop and gdp summarize pop,detail scalar popmean = r(mean) scalar popmed = r(p50) scalar pop75 = r(p75) summarize gdp,detail scalar gdpmean = r(mean) scalar gdpmed = r(p50) scalar gdp75 = r(p75) * create logs generate lpop = log(pop) generate lgdp = log(gdp) * estimate poisson model poisson medaltot lpop lgdp * logs of median values di "log(popmed) = " log(5921270) di "log(gdpmed) = " log(5.51e+09) * marginal effects at logs of median values mfx, at(lpop=15.594062 lgdp=22.42983) mfx, at(median) * Predicted number at medians nlcom(exp(_b[_cons]+_b[lpop]*log(popmed) + _b[lgdp]*log(gdpmed))) * gdp at median and pop at 75 pct nlcom(exp(_b[_cons]+_b[lpop]*log(pop75) + _b[lgdp]*log(gdpmed))) * pop at med and gdp at 75% nlcom(exp(_b[_cons]+_b[lpop]*log(popmed) + _b[lgdp]*log(gdp75))) * GBR nlcom(exp(_b[_cons]+_b[lpop]*log(5.72e+7) + _b[lgdp]*log(1.01e+12))) *---------------------------- * tobit simulated data *---------------------------- use tobit, clear * examine data summarize summarize if y>0 * regression reg y x reg y x if y>0 * tobit tobit y x, ll *---------------------------- * tobit mroz data *---------------------------- use mroz, clear * examine data summarize lfp hours educ exper age kidsl6 histogram hours, frequency more summarize hours educ exper age kidsl6 if (hours>0) summarize hours educ exper age kidsl6 if (hours==0) * regression regress hours educ exper age kidsl6 regress hours educ exper age kidsl6 if (hours>0) * tobit tobit hours educ exper age kidsl6, ll * tobit scale factor scalar xb = _b[_cons]+_b[educ]*12.29+_b[exper]*10.63+_b[age]*42.5+_b[kidsl6]*1 display "x*beta " xb scalar cdf = normal( xb/_b[/sigma]) display "Tobit scale Factor: cdf evaluated at zi = " cdf *---------------------------- * heckit *---------------------------- use mroz, clear generate lwage = log(wage) * ols regress lwage educ exper if (hours>0) * probit generate kids = (kidsl6+kids618>0) probit lfp age educ kids mtr predict w, xb * Inverse Mills Ratio generate imr = normalden(w)/normal(w) * Heckit two-step regress lwage educ exper imr * Heckit two-step automatic heckman lwage educ exper, select(lfp=age educ kids mtr) twostep * Heckit maximum likelihood heckman lwage educ exper, select(lfp=age educ kids mtr) log close translate chap16.smcl chap16.txt