--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- name: log: /Users/kleintob/Documents/GitHub/econometricsResearchMaster/notes for lectures in class/stata 2 ordered choice.log log type: text opened on: 9 May 2026, 10:17:59 . . . . . /* > example taken from https://www.stata.com/manuals13/roprobit.pdf > */ . . . . . * data . use http://www.stata-press.com/data/r13/fullauto, clear (Automobile Models) . describe Contains data from http://www.stata-press.com/data/r13/fullauto.dta Observations: 74 Automobile Models Variables: 18 3 Mar 2013 06:53 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Variable Storage Display Value name type format label Variable label --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- make int %8.0g make Make model int %8.0g model Model price int %8.0g Price mpg int %8.0g Mileage (mpg) rep78 int %9.0g repair Repair Record 1978 rep77 int %9.0g repair Repair Record 1977 hdroom float %6.1f Headroom (in.) rseat float %6.1f Rear Seat (in.) trunk int %8.0g Trunk space (cu. ft.) weight int %8.0g Weight (lbs.) length int %8.0g Length (in.) turn int %8.0g Turn Circle (ft.) displ int %8.0g Displacement (cu. in.) gratio float %6.2f Gear Ratio order int %8.0g Original order foreign int %8.0g foreign Foreign wgtd float %9.0g wgtf float %9.0g --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sorted by: make model . tab rep77 Repair | Record 1977 | Freq. Percent Cum. ------------+----------------------------------- Poor | 3 4.55 4.55 Fair | 11 16.67 21.21 Average | 27 40.91 62.12 Good | 20 30.30 92.42 Excellent | 5 7.58 100.00 ------------+----------------------------------- Total | 66 100.00 . . . . . * estimate models, first linear regression . regress rep77 foreign length mpg Source | SS df MS Number of obs = 66 -------------+---------------------------------- F(3, 62) = 8.72 Model | 17.9412901 3 5.98043005 Prob > F = 0.0001 Residual | 42.4981038 62 .685453287 R-squared = 0.2968 -------------+---------------------------------- Adj R-squared = 0.2628 Total | 60.4393939 65 .92983683 Root MSE = .82792 ------------------------------------------------------------------------------ rep77 | Coefficient Std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- foreign | 1.240631 .2974202 4.17 0.000 .6460968 1.835166 length | .0348262 .0089513 3.89 0.000 .0169328 .0527196 mpg | .0959636 .0269229 3.56 0.001 .0421455 .1497817 _cons | -5.831377 2.199401 -2.65 0.010 -10.22792 -1.434837 ------------------------------------------------------------------------------ . regress rep77 foreign length mpg, vce(robust) Linear regression Number of obs = 66 F(3, 62) = 11.28 Prob > F = 0.0000 R-squared = 0.2968 Root MSE = .82792 ------------------------------------------------------------------------------ | Robust rep77 | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- foreign | 1.240631 .3344735 3.71 0.000 .5720283 1.909234 length | .0348262 .0089336 3.90 0.000 .0169681 .0526843 mpg | .0959636 .0296697 3.23 0.002 .0366547 .1552725 _cons | -5.831377 2.235816 -2.61 0.011 -10.30071 -1.362043 ------------------------------------------------------------------------------ . . . . . * ordered logit . ologit rep77 i.foreign length mpg // foreign is discrete, matters for marginal effects Iteration 0: Log likelihood = -89.895098 Iteration 1: Log likelihood = -78.775147 Iteration 2: Log likelihood = -78.254294 Iteration 3: Log likelihood = -78.250719 Iteration 4: Log likelihood = -78.250719 Ordered logistic regression Number of obs = 66 LR chi2(3) = 23.29 Prob > chi2 = 0.0000 Log likelihood = -78.250719 Pseudo R2 = 0.1295 ------------------------------------------------------------------------------ rep77 | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- foreign | Foreign | 2.896807 .7906411 3.66 0.000 1.347179 4.446435 length | .0828275 .02272 3.65 0.000 .0382972 .1273579 mpg | .2307677 .0704548 3.28 0.001 .0926788 .3688566 -------------+---------------------------------------------------------------- /cut1 | 17.92748 5.551191 7.047344 28.80761 /cut2 | 19.86506 5.59648 8.896161 30.83396 /cut3 | 22.10331 5.708936 10.914 33.29262 /cut4 | 24.69213 5.890754 13.14647 36.2378 ------------------------------------------------------------------------------ . margins, dydx(*) // marginal effects Average marginal effects Number of obs = 66 Model VCE: OIM dy/dx wrt: 1.foreign length mpg 1._predict: Pr(rep77==1), predict(pr outcome(1)) 2._predict: Pr(rep77==2), predict(pr outcome(2)) 3._predict: Pr(rep77==3), predict(pr outcome(3)) 4._predict: Pr(rep77==4), predict(pr outcome(4)) 5._predict: Pr(rep77==5), predict(pr outcome(5)) ------------------------------------------------------------------------------ | Delta-method | dy/dx std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- 0.foreign | (base outcome) -------------+---------------------------------------------------------------- 1.foreign | _predict | 1 | -.0960131 .0515044 -1.86 0.062 -.1969599 .0049336 2 | -.2133594 .0581308 -3.67 0.000 -.3272936 -.0994252 3 | -.2122597 .0654808 -3.24 0.001 -.3405998 -.0839197 4 | .2701893 .0811171 3.33 0.001 .1112027 .4291758 5 | .251443 .1119336 2.25 0.025 .0320572 .4708287 -------------+---------------------------------------------------------------- length | _predict | 1 | -.0033909 .0018734 -1.81 0.070 -.0070626 .0002808 2 | -.0084022 .0026239 -3.20 0.001 -.0135449 -.0032595 3 | -.0033174 .0022648 -1.46 0.143 -.0077563 .0011215 4 | .0105045 .0027914 3.76 0.000 .0050334 .0159755 5 | .0046061 .0018282 2.52 0.012 .001023 .0081893 -------------+---------------------------------------------------------------- mpg | _predict | 1 | -.0094475 .0053206 -1.78 0.076 -.0198757 .0009807 2 | -.0234096 .0084882 -2.76 0.006 -.0400461 -.0067731 3 | -.0092428 .0062626 -1.48 0.140 -.0215173 .0030317 4 | .0292667 .0094344 3.10 0.002 .0107756 .0477578 5 | .0128332 .0049252 2.61 0.009 .0031799 .0224864 ------------------------------------------------------------------------------ Note: dy/dx for factor levels is the discrete change from the base level. . . . . . * ordered probit (from now on until end) . oprobit rep77 i.foreign length mpg // foreign is discrete, matters for marginal effects Iteration 0: Log likelihood = -89.895098 Iteration 1: Log likelihood = -78.106316 Iteration 2: Log likelihood = -78.020086 Iteration 3: Log likelihood = -78.020025 Iteration 4: Log likelihood = -78.020025 Ordered probit regression Number of obs = 66 LR chi2(3) = 23.75 Prob > chi2 = 0.0000 Log likelihood = -78.020025 Pseudo R2 = 0.1321 ------------------------------------------------------------------------------ rep77 | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- foreign | Foreign | 1.704861 .4246796 4.01 0.000 .8725037 2.537217 length | .0468675 .012648 3.71 0.000 .022078 .0716571 mpg | .1304559 .0378628 3.45 0.001 .0562463 .2046656 -------------+---------------------------------------------------------------- /cut1 | 10.1589 3.076754 4.128577 16.18923 /cut2 | 11.21003 3.107527 5.119389 17.30067 /cut3 | 12.54561 3.155233 6.361467 18.72975 /cut4 | 13.98059 3.218793 7.671874 20.28931 ------------------------------------------------------------------------------ . margins, dydx(*) // marginal effects Average marginal effects Number of obs = 66 Model VCE: OIM dy/dx wrt: 1.foreign length mpg 1._predict: Pr(rep77==1), predict(pr outcome(1)) 2._predict: Pr(rep77==2), predict(pr outcome(2)) 3._predict: Pr(rep77==3), predict(pr outcome(3)) 4._predict: Pr(rep77==4), predict(pr outcome(4)) 5._predict: Pr(rep77==5), predict(pr outcome(5)) ------------------------------------------------------------------------------ | Delta-method | dy/dx std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- 0.foreign | (base outcome) -------------+---------------------------------------------------------------- 1.foreign | _predict | 1 | -.1038936 .0498472 -2.08 0.037 -.2015922 -.006195 2 | -.2115781 .0560295 -3.78 0.000 -.321394 -.1017623 3 | -.2088929 .0631238 -3.31 0.001 -.3326134 -.0851725 4 | .2458694 .0732963 3.35 0.001 .1022113 .3895275 5 | .2784953 .1016554 2.74 0.006 .0792542 .4777363 -------------+---------------------------------------------------------------- length | _predict | 1 | -.0037758 .0018959 -1.99 0.046 -.0074917 -.00006 2 | -.0077182 .0024668 -3.13 0.002 -.0125532 -.0028833 3 | -.0030079 .0019491 -1.54 0.123 -.0068281 .0008124 4 | .0095114 .0025294 3.76 0.000 .0045538 .0144689 5 | .0049906 .001919 2.60 0.009 .0012294 .0087517 -------------+---------------------------------------------------------------- mpg | _predict | 1 | -.01051 .0053399 -1.97 0.049 -.020976 -.000044 2 | -.0214837 .0076255 -2.82 0.005 -.0364295 -.0065379 3 | -.0083724 .0053433 -1.57 0.117 -.0188451 .0021003 4 | .0264749 .0079897 3.31 0.001 .0108153 .0421345 5 | .0138913 .005251 2.65 0.008 .0035996 .024183 ------------------------------------------------------------------------------ Note: dy/dx for factor levels is the discrete change from the base level. . . matrix b = e(b) // save coefficients . margins, dydx(*) // marginal effects Average marginal effects Number of obs = 66 Model VCE: OIM dy/dx wrt: 1.foreign length mpg 1._predict: Pr(rep77==1), predict(pr outcome(1)) 2._predict: Pr(rep77==2), predict(pr outcome(2)) 3._predict: Pr(rep77==3), predict(pr outcome(3)) 4._predict: Pr(rep77==4), predict(pr outcome(4)) 5._predict: Pr(rep77==5), predict(pr outcome(5)) ------------------------------------------------------------------------------ | Delta-method | dy/dx std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- 0.foreign | (base outcome) -------------+---------------------------------------------------------------- 1.foreign | _predict | 1 | -.1038936 .0498472 -2.08 0.037 -.2015922 -.006195 2 | -.2115781 .0560295 -3.78 0.000 -.321394 -.1017623 3 | -.2088929 .0631238 -3.31 0.001 -.3326134 -.0851725 4 | .2458694 .0732963 3.35 0.001 .1022113 .3895275 5 | .2784953 .1016554 2.74 0.006 .0792542 .4777363 -------------+---------------------------------------------------------------- length | _predict | 1 | -.0037758 .0018959 -1.99 0.046 -.0074917 -.00006 2 | -.0077182 .0024668 -3.13 0.002 -.0125532 -.0028833 3 | -.0030079 .0019491 -1.54 0.123 -.0068281 .0008124 4 | .0095114 .0025294 3.76 0.000 .0045538 .0144689 5 | .0049906 .001919 2.60 0.009 .0012294 .0087517 -------------+---------------------------------------------------------------- mpg | _predict | 1 | -.01051 .0053399 -1.97 0.049 -.020976 -.000044 2 | -.0214837 .0076255 -2.82 0.005 -.0364295 -.0065379 3 | -.0083724 .0053433 -1.57 0.117 -.0188451 .0021003 4 | .0264749 .0079897 3.31 0.001 .0108153 .0421345 5 | .0138913 .005251 2.65 0.008 .0035996 .024183 ------------------------------------------------------------------------------ Note: dy/dx for factor levels is the discrete change from the base level. . . . . . * construct figure corresponding to slide 55 for ordered probit model . . ** do it for mean of xb . predict xb_hat, xb . summarize xb_hat, meanonly . scalar xb_mean = r(mean) . . ** extract thresholds . matrix b = e(b) . scalar c1 = b[1,"/cut1"] . scalar c2 = b[1,"/cut2"] . scalar c3 = b[1,"/cut3"] . scalar c4 = b[1,"/cut4"] . . ** compute cutoffs mean of xb minus alphas . scalar z1 = c1 - xb_mean . scalar z2 = c2 - xb_mean . scalar z3 = c3 - xb_mean . scalar z4 = c4 - xb_mean . . ** generate standard normal density . clear . set obs 1000 Number of observations (_N) was 0, now 1,000. . gen z = -4 + (_n-1)*8/999 . gen f = normalden(z) . . * plot density with vertical lines at shifted thresholds . twoway (line f z, sort), /// > xline(`=z1' `=z2' `=z3' `=z4', lpattern(dash) lcolor(gs8)) /// > ytitle("density") xtitle("epsilon") /// > title("") /// > legend(off) . . . . . log close name: log: /Users/kleintob/Documents/GitHub/econometricsResearchMaster/notes for lectures in class/stata 2 ordered choice.log log type: text closed on: 9 May 2026, 10:18:01 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------