------------------------------------------------------------------------------------------------------------- log: d:\spost.stata8\do\st8ch8.log log type: text opened on: 26 May 2003, 12:53:17 . . // * . // * RM4STATA Ch 8: Additional Topics - 5/26/2003 . // * . . // * section 8.1: ordinal and nominal independent variables . . * create two variables that will be used later . * create mentord from ment . use couart2, clear (Academic Biochemists / S Long) . gen mentord = ment . recode mentord 0=0 .9/3=1 3.5/9=2 9.5/20=3 20.1/1000=4 (mentord: 773 changes made) . label var mentord "Ordinal measure of mentor's articles" . label def lment 0 None 1 Few 2 Some 3 Many 4 Lots . label val mentord lment . tab mentord, missing Ordinal | measure of | mentor's | articles | Freq. Percent Cum. ------------+----------------------------------- None | 90 9.84 9.84 Few | 201 21.97 31.80 Some | 324 35.41 67.21 Many | 213 23.28 90.49 Lots | 87 9.51 100.00 ------------+----------------------------------- Total | 915 100.00 . * create binary outcome hasarts from art . gen hasarts = (art >0) if art < . . label var hasarts "Has publised: 1=yes 0=no" . label define lhasarts 0 NoArts 1 Arts . label values hasarts lhasarts . tab hasarts, m Has | publised: | 1=yes 0=no | Freq. Percent Cum. ------------+----------------------------------- NoArts | 275 30.05 30.05 Arts | 640 69.95 100.00 ------------+----------------------------------- Total | 915 100.00 . sum hasarts art fem mar kid5 phd ment Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- hasarts | 915 .6994536 .4587464 0 1 art | 915 1.692896 1.926069 0 19 fem | 915 .4601093 .4986788 0 1 mar | 915 .6622951 .473186 0 1 kid5 | 915 .495082 .76488 0 3 -------------+-------------------------------------------------------- phd | 915 3.103109 .9842491 .755 4.62 ment | 915 8.767213 9.483916 0 77 . . // * section 8.1.1: coding categorical variables as dummy variables . . gen none = (mentord == 0) if mentord < . . tab none mentord, missing | Ordinal measure of mentor's articles none | None Few Some Many Lots | Total -----------+-------------------------------------------------------+---------- 0 | 0 201 324 213 87 | 825 1 | 90 0 0 0 0 | 90 -----------+-------------------------------------------------------+---------- Total | 90 201 324 213 87 | 915 . gen few = (mentord == 1) if mentord < . . gen some = (mentord == 2) if mentord < . . gen many = (mentord == 3) if mentord < . . gen lots = (mentord == 4) if mentord < . . . // * section 8.1.2: estimation and interpretation . . * estimate logit model without excluding any dummies . logit hasarts fem mar kid5 phd none few some many lots, nolog note: lots dropped due to collinearity Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 none | -2.335227 .4368715 -5.35 0.000 -3.19148 -1.478975 few | -1.949312 .4028682 -4.84 0.000 -2.73892 -1.159705 some | -1.37501 .3945447 -3.49 0.000 -2.148303 -.6017161 many | -.8716209 .4104651 -2.12 0.034 -1.676118 -.0671242 _cons | 2.283108 .4986307 4.58 0.000 1.30581 3.260407 ------------------------------------------------------------------------------ . . * estimate logit with j-1 dummy variables, excluding none . logit hasarts fem mar kid5 phd few some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 few | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .9602176 .2490498 3.86 0.000 .4720889 1.448346 many | 1.463606 .2829625 5.17 0.000 .9090099 2.018203 lots | 2.335227 .4368715 5.35 0.000 1.478975 3.19148 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . listcoef logit (N=915): Factor Change in Odds Odds of: Arts vs NoArts ---------------------------------------------------------------------- hasarts | b z P>|z| e^b e^bStdX SDofX -------------+-------------------------------------------------------- fem | -0.25793 -1.611 0.107 0.7726 0.8793 0.4987 mar | 0.33008 1.812 0.070 1.3911 1.1690 0.4732 kid5 | -0.27958 -2.499 0.012 0.7561 0.8075 0.7649 phd | 0.01217 0.152 0.879 1.0122 1.0121 0.9842 few | 0.38591 1.492 0.136 1.4710 1.1734 0.4143 some | 0.96022 3.856 0.000 2.6123 1.5832 0.4785 many | 1.46361 5.172 0.000 4.3215 1.8568 0.4228 lots | 2.33523 5.345 0.000 10.3318 1.9845 0.2935 ---------------------------------------------------------------------- . . * comparing many to some by excluding some . logit hasarts fem mar kid5 phd none few many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 none | -.9602176 .2490498 -3.86 0.000 -1.448346 -.4720889 few | -.5743029 .1897376 -3.03 0.002 -.9461818 -.2024241 many | .5033886 .2143001 2.35 0.019 .0833682 .9234091 lots | 1.37501 .3945447 3.49 0.000 .6017161 2.148303 _cons | .9080989 .3182603 2.85 0.004 .2843202 1.531878 ------------------------------------------------------------------------------ . . // * section 8.1.3: tests with categorical independent variables . . * testing two non-reference categories . logit hasarts fem mar kid5 phd few some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 few | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .9602176 .2490498 3.86 0.000 .4720889 1.448346 many | 1.463606 .2829625 5.17 0.000 .9090099 2.018203 lots | 2.335227 .4368715 5.35 0.000 1.478975 3.19148 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . lincom many-some ( 1) - some + many = 0 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- (1) | .5033886 .2143001 2.35 0.019 .0833682 .9234091 ------------------------------------------------------------------------------ . . * LR test that a categorical variable has no effect . logit hasarts fem mar kid5 phd few some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 few | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .9602176 .2490498 3.86 0.000 .4720889 1.448346 many | 1.463606 .2829625 5.17 0.000 .9090099 2.018203 lots | 2.335227 .4368715 5.35 0.000 1.478975 3.19148 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . estimates store fmodel . logit hasarts fem mar kid5 phd, nolog Logit estimates Number of obs = 915 LR chi2(4) = 15.48 Prob > chi2 = 0.0038 Log likelihood = -551.62577 Pseudo R2 = 0.0138 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.3103903 .155124 -2.00 0.045 -.6144278 -.0063528 mar | .2997893 .1769683 1.69 0.090 -.0470622 .6466408 kid5 | -.2721801 .1086893 -2.50 0.012 -.4852072 -.059153 phd | .1795331 .0744986 2.41 0.016 .0335186 .3255477 _cons | .3827982 .2872164 1.33 0.183 -.1801355 .9457319 ------------------------------------------------------------------------------ . lrtest fmodel likelihood-ratio test LR chi2(4) = 58.32 (Assumption: . nested in fmodel) Prob > chi2 = 0.0000 . . * Wald test that a categorical variable has no effect . logit hasarts fem mar kid5 phd few some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 few | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .9602176 .2490498 3.86 0.000 .4720889 1.448346 many | 1.463606 .2829625 5.17 0.000 .9090099 2.018203 lots | 2.335227 .4368715 5.35 0.000 1.478975 3.19148 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . test few some many lots ( 1) few = 0 ( 2) some = 0 ( 3) many = 0 ( 4) lots = 0 chi2( 4) = 51.60 Prob > chi2 = 0.0000 . . * LR test whether treating ordinal var as interval loses info . logit hasarts fem mar kid5 phd mentord some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 mentord | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .1883882 .3791708 0.50 0.619 -.5547728 .9315493 many | .3058622 .6311175 0.48 0.628 -.9311053 1.54283 lots | .7915684 .937771 0.84 0.399 -1.046429 2.629566 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . estimates store fmodel . logit hasarts fem mar kid5 phd mentord, nolog Logit estimates Number of obs = 915 LR chi2(5) = 72.73 Prob > chi2 = 0.0000 Log likelihood = -522.99932 Pseudo R2 = 0.0650 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.266308 .1598617 -1.67 0.096 -.5796312 .0470153 mar | .3329119 .1823256 1.83 0.068 -.0244397 .6902635 kid5 | -.2812119 .1118409 -2.51 0.012 -.500416 -.0620078 phd | .0100783 .0802174 0.13 0.900 -.147145 .1673016 mentord | .5429222 .0747143 7.27 0.000 .3964848 .6893595 _cons | -.1553251 .3050814 -0.51 0.611 -.7532736 .4426234 ------------------------------------------------------------------------------ . lrtest fmodel likelihood-ratio test LR chi2(3) = 1.07 (Assumption: . nested in fmodel) Prob > chi2 = 0.7845 . . * LR test whether treating ordinal var as interval loses info . logit hasarts fem mar kid5 phd mentord some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 mentord | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .1883882 .3791708 0.50 0.619 -.5547728 .9315493 many | .3058622 .6311175 0.48 0.628 -.9311053 1.54283 lots | .7915684 .937771 0.84 0.399 -1.046429 2.629566 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . test some many lots ( 1) some = 0 ( 2) many = 0 ( 3) lots = 0 chi2( 3) = 1.03 Prob > chi2 = 0.7950 . . // * section 8.1.4: discrete change for categorical independent variables . . * computing discrete change with -prchange- . logit hasarts fem mar kid5 phd few some many lots, nolog Logit estimates Number of obs = 915 LR chi2(8) = 73.80 Prob > chi2 = 0.0000 Log likelihood = -522.46467 Pseudo R2 = 0.0660 ------------------------------------------------------------------------------ hasarts | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- fem | -.2579293 .1601187 -1.61 0.107 -.5717562 .0558976 mar | .3300817 .1822141 1.81 0.070 -.0270514 .6872147 kid5 | -.2795751 .1118578 -2.50 0.012 -.4988123 -.0603379 phd | .0121703 .0802726 0.15 0.879 -.145161 .1695017 few | .3859147 .2586461 1.49 0.136 -.1210223 .8928517 some | .9602176 .2490498 3.86 0.000 .4720889 1.448346 many | 1.463606 .2829625 5.17 0.000 .9090099 2.018203 lots | 2.335227 .4368715 5.35 0.000 1.478975 3.19148 _cons | -.0521187 .3361977 -0.16 0.877 -.7110542 .6068167 ------------------------------------------------------------------------------ . prchange few, x(some=0 many=0 lots=0) logit: Changes in Predicted Probabilities for hasarts min->max 0->1 -+1/2 -+sd/2 MargEfct few 0.0957 0.0957 0.0962 0.0399 0.0965 NoArts Arts Pr(y|x) 0.4920 0.5080 fem mar kid5 phd few some many lots x= .460109 .662295 .495082 3.10311 .219672 0 0 0 sd(x)= .498679 .473186 .76488 .984249 .414251 .478501 .422839 .293489 . . * NOTE: the following does NOT work !! . prchange few logit: Changes in Predicted Probabilities for hasarts min->max 0->1 -+1/2 -+sd/2 MargEfct few 0.0743 0.0743 0.0780 0.0324 0.0781 NoArts Arts Pr(y|x) 0.2820 0.7180 fem mar kid5 phd few some many lots x= .460109 .662295 .495082 3.10311 .219672 .354098 .232787 .095082 sd(x)= .498679 .473186 .76488 .984249 .414251 .478501 .422839 .293489 . . * -prvalue- with two non-reference categories . quietly prvalue, x(few=1 some=0 many=0 lots=0) save . prvalue, x(few=0 some=1 many=0 lots=0) dif logit: Change in Predictions for hasarts Current Saved Difference Pr(y=Arts|x): 0.7125 0.5825 0.1300 Pr(y=NoArts|x): 0.2875 0.4175 -0.1300 fem mar kid5 phd few some many lots Current= .46010929 .66229508 .49508197 3.1031093 0 1 0 0 Saved= .46010929 .66229508 .49508197 3.1031093 1 0 0 0 Diff= 0 0 0 0 -1 1 0 0 . . * NOTE: the following does NOT work !! . prchange some, x(few=1 some=0 many=0 lots=0) logit: Changes in Predicted Probabilities for hasarts min->max 0->1 -+1/2 -+sd/2 MargEfct some 0.2022 0.2022 0.2295 0.1113 0.2335 NoArts Arts Pr(y|x) 0.4175 0.5825 fem mar kid5 phd few some many lots x= .460109 .662295 .495082 3.10311 1 0 0 0 sd(x)= .498679 .473186 .76488 .984249 .414251 .478501 .422839 .293489 . . // * section 8.2: interactions . . * estimate model with interaction . use ordwarm2.dta, clear (77 & 89 General Social Survey) . gen maleXed = male*ed . ologit warm age prst yr89 white male ed maleXed, nolog Ordered logit estimates Number of obs = 2293 LR chi2(7) = 305.30 Prob > chi2 = 0.0000 Log likelihood = -2843.1198 Pseudo R2 = 0.0510 ------------------------------------------------------------------------------ warm | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | -.0212523 .0024775 -8.58 0.000 -.0261082 -.0163965 prst | .0052597 .0033198 1.58 0.113 -.001247 .0117664 yr89 | .5238686 .0799287 6.55 0.000 .3672111 .680526 white | -.3908743 .1184189 -3.30 0.001 -.622971 -.1587776 male | -.1505216 .3176105 -0.47 0.636 -.7730268 .4719836 ed | .0976341 .0226886 4.30 0.000 .0531651 .142103 maleXed | -.047534 .0251183 -1.89 0.058 -.0967649 .001697 -------------+---------------------------------------------------------------- _cut1 | -2.107903 .3043008 (Ancillary parameters) _cut2 | -.2761098 .2992857 _cut3 | 1.621787 .3018749 ------------------------------------------------------------------------------ . . * LR test of interaction . quietly ologit warm age prst yr89 white male ed maleXed, nolog . estimates store fmodel . quietly ologit warm age prst yr89 white male ed, nolog . lrtest fmodel likelihood-ratio test LR chi2(1) = 3.59 (Assumption: . nested in fmodel) Prob > chi2 = 0.0583 . . // * section 8.2.1: computing gender differences in predictions . * with interactions . . * predictions for women . ologit warm age prst yr89 white male ed maleXed, nolog Ordered logit estimates Number of obs = 2293 LR chi2(7) = 305.30 Prob > chi2 = 0.0000 Log likelihood = -2843.1198 Pseudo R2 = 0.0510 ------------------------------------------------------------------------------ warm | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | -.0212523 .0024775 -8.58 0.000 -.0261082 -.0163965 prst | .0052597 .0033198 1.58 0.113 -.001247 .0117664 yr89 | .5238686 .0799287 6.55 0.000 .3672111 .680526 white | -.3908743 .1184189 -3.30 0.001 -.622971 -.1587776 male | -.1505216 .3176105 -0.47 0.636 -.7730268 .4719836 ed | .0976341 .0226886 4.30 0.000 .0531651 .142103 maleXed | -.047534 .0251183 -1.89 0.058 -.0967649 .001697 -------------+---------------------------------------------------------------- _cut1 | -2.107903 .3043008 (Ancillary parameters) _cut2 | -.2761098 .2992857 _cut3 | 1.621787 .3018749 ------------------------------------------------------------------------------ . prvalue, x(male=0 maleXed=0) rest(mean) save ologit: Predictions for warm Pr(y=SD|x): 0.0816 Pr(y=D|x): 0.2754 Pr(y=A|x): 0.4304 Pr(y=SA|x): 0.2126 age prst yr89 white male ed maleXed x= 44.935456 39.585259 .39860445 .8765809 0 12.218055 0 . . * predictions for men . sum ed Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- ed | 2293 12.21805 3.160827 0 20 . global meaned = r(mean) . prvalue, x(male=1 maleXed=$meaned) dif ologit: Change in Predictions for warm Current Saved Difference Pr(y=SD|x): 0.1559 0.0816 0.0743 Pr(y=D|x): 0.3797 0.2754 0.1044 Pr(y=A|x): 0.3494 0.4304 -0.0811 Pr(y=SA|x): 0.1150 0.2126 -0.0976 age prst yr89 white male ed maleXed Current= 44.935456 39.585259 .39860445 .8765809 1 12.218055 12.218055 Saved= 44.935456 39.585259 .39860445 .8765809 0 12.218055 0 Diff= 0 0 0 0 1 0 12.218055 . . * alternatively: predictions without using globals . prvalue, x(male=1 maleXed=12.21805) dif ologit: Change in Predictions for warm Current Saved Difference Pr(y=SD|x): 0.1559 0.0816 0.0743 Pr(y=D|x): 0.3797 0.2754 0.1044 Pr(y=A|x): 0.3494 0.4304 -0.0811 Pr(y=SA|x): 0.1150 0.2126 -0.0976 age prst yr89 white male ed maleXed Current= 44.935456 39.585259 .39860445 .8765809 1 12.218055 12.21805 Saved= 44.935456 39.585259 .39860445 .8765809 0 12.218055 0 Diff= 0 0 0 0 1 0 12.21805 . . // * section 8.2.2: computing gender differences in discrete change . . * for women . quietly prvalue, x(male=0 maleXed=0 ed=12) rest(mean) save . prvalue, x(male=0 maleXed=0 ed=16) rest(mean) dif ologit: Change in Predictions for warm Current Saved Difference Pr(y=SD|x): 0.0579 0.0833 -0.0254 Pr(y=D|x): 0.2194 0.2786 -0.0592 Pr(y=A|x): 0.4418 0.4291 0.0127 Pr(y=SA|x): 0.2809 0.2090 0.0718 age prst yr89 white male ed maleXed Current= 44.935456 39.585259 .39860445 .8765809 0 16 0 Saved= 44.935456 39.585259 .39860445 .8765809 0 12 0 Diff= 0 0 0 0 0 4 0 . * for men . quietly prvalue, x(male=1 maleXed=12 ed=12) rest(mean) save . prvalue, x(male=1 maleXed=16 ed=16) rest(mean) dif ologit: Change in Predictions for warm Current Saved Difference Pr(y=SD|x): 0.1326 0.1574 -0.0248 Pr(y=D|x): 0.3558 0.3810 -0.0252 Pr(y=A|x): 0.3759 0.3477 0.0282 Pr(y=SA|x): 0.1357 0.1139 0.0218 age prst yr89 white male ed maleXed Current= 44.935456 39.585259 .39860445 .8765809 1 16 16 Saved= 44.935456 39.585259 .39860445 .8765809 1 12 12 Diff= 0 0 0 0 0 4 4 . . // * section 8.3.1: adding nonlinearities to linear predictors . . * construct graph from this section . graph twoway function y = 1 -.1*x + .1*x^2, range(0 100) . graph export 08nonlinear.eps, replace (file 08nonlinear.eps written in .eps format) . . // * section 8.3.1: discrete change in nonlinear nonlinear models . . * discrete change without age2 . use binlfp2,clear (Data from 1976 PSID-T Mroz) . logit lfp k5 k618 wc hc lwg inc age, nolog Logit estimates Number of obs = 753 LR chi2(7) = 124.48 Prob > chi2 = 0.0000 Log likelihood = -452.63296 Pseudo R2 = 0.1209 ------------------------------------------------------------------------------ lfp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- k5 | -1.462913 .1970006 -7.43 0.000 -1.849027 -1.076799 k618 | -.0645707 .0680008 -0.95 0.342 -.1978499 .0687085 wc | .8072738 .2299799 3.51 0.000 .3565215 1.258026 hc | .1117336 .2060397 0.54 0.588 -.2920969 .515564 lwg | .6046931 .1508176 4.01 0.000 .3090961 .9002901 inc | -.0344464 .0082084 -4.20 0.000 -.0505346 -.0183583 age | -.0628706 .0127831 -4.92 0.000 -.0879249 -.0378162 _cons | 3.18214 .6443751 4.94 0.000 1.919188 4.445092 ------------------------------------------------------------------------------ . prchange age, x(age=30) delta(20) uncentered logit: Changes in Predicted Probabilities for lfp (Note: delta = 20) min->max 0->1 +delta +sd MargEfct age -0.4372 -0.0030 -0.2894 -0.1062 -0.0118 NotInLF inLF Pr(y|x) 0.2494 0.7506 k5 k618 wc hc lwg inc age x= .237716 1.35325 .281541 .391766 1.09711 20.129 30 sd(x)= .523959 1.31987 .450049 .488469 .587556 11.6348 8.07257 . . * adding age2 to the model . gen age2 = age*age . logit lfp k5 k618 wc hc lwg inc age age2, nolog Logit estimates Number of obs = 753 LR chi2(8) = 125.67 Prob > chi2 = 0.0000 Log likelihood = -452.03836 Pseudo R2 = 0.1220 ------------------------------------------------------------------------------ lfp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- k5 | -1.411597 .2001829 -7.05 0.000 -1.803948 -1.019246 k618 | -.0815087 .0696247 -1.17 0.242 -.2179706 .0549531 wc | .8098626 .2299065 3.52 0.000 .3592542 1.260471 hc | .1340998 .207023 0.65 0.517 -.2716579 .5398575 lwg | .5925741 .1507807 3.93 0.000 .2970495 .8880988 inc | -.0355964 .0083188 -4.28 0.000 -.0519009 -.0192919 age | .0659135 .1188199 0.55 0.579 -.1669693 .2987962 age2 | -.0014784 .0013584 -1.09 0.276 -.0041408 .001184 _cons | .511489 2.527194 0.20 0.840 -4.44172 5.464698 ------------------------------------------------------------------------------ . . * LR test for age and age2 . quietly logit lfp k5 k618 wc hc lwg inc age age2, nolog . estimates store fmodel . quietly logit lfp k5 k618 wc hc lwg inc, nolog . lrtest fmodel likelihood-ratio test LR chi2(2) = 26.79 (Assumption: . nested in fmodel) Prob > chi2 = 0.0000 . . * discrete change with age2 . logit lfp k5 k618 wc hc lwg inc age age2, nolog Logit estimates Number of obs = 753 LR chi2(8) = 125.67 Prob > chi2 = 0.0000 Log likelihood = -452.03836 Pseudo R2 = 0.1220 ------------------------------------------------------------------------------ lfp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- k5 | -1.411597 .2001829 -7.05 0.000 -1.803948 -1.019246 k618 | -.0815087 .0696247 -1.17 0.242 -.2179706 .0549531 wc | .8098626 .2299065 3.52 0.000 .3592542 1.260471 hc | .1340998 .207023 0.65 0.517 -.2716579 .5398575 lwg | .5925741 .1507807 3.93 0.000 .2970495 .8880988 inc | -.0355964 .0083188 -4.28 0.000 -.0519009 -.0192919 age | .0659135 .1188199 0.55 0.579 -.1669693 .2987962 age2 | -.0014784 .0013584 -1.09 0.276 -.0041408 .001184 _cons | .511489 2.527194 0.20 0.840 -4.44172 5.464698 ------------------------------------------------------------------------------ . . * predictions at age 30 . global age30 = 30 . global age30sq = $age30*$age30 . quietly prvalue, x(age=$age30 age2=$age30sq) rest(mean) save . * predictions at age 50 . global age50 = 50 . global age50sq = $age50*$age50 . prvalue, x(age=$age50 age2=$age50sq) rest(mean) dif logit: Change in Predictions for lfp Current Saved Difference Pr(y=inLF|x): 0.4699 0.7164 -0.2465 Pr(y=NotInLF|x): 0.5301 0.2836 0.2465 k5 k618 wc hc lwg inc age age2 Current= .2377158 1.3532537 .2815405 .39176627 1.0971148 20.128965 50 2500 Saved= .2377158 1.3532537 .2815405 .39176627 1.0971148 20.128965 30 900 Diff= 0 0 0 0 0 0 20 1600 . . // * section 8.4.1: example using age and age squared . . * use -prgen- in model with only age; plot results later . use binlfp2,clear (Data from 1976 PSID-T Mroz) . quietly logit lfp k5 k618 age wc hc lwg inc . prgen age, from(20) to(60) gen(prage) ncases(9) logit: Predicted values as age varies from 20 to 60. k5 k618 age wc hc lwg inc x= .2377158 1.3532537 42.537849 .2815405 .39176627 1.0971148 20.128965 . label var pragep1 "Pr(lpf | age)" . . * estimate model with age squared . gen age2 = age*age . logit lfp k5 k618 age age2 wc hc lwg inc, nolog Logit estimates Number of obs = 753 LR chi2(8) = 125.67 Prob > chi2 = 0.0000 Log likelihood = -452.03836 Pseudo R2 = 0.1220 ------------------------------------------------------------------------------ lfp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- k5 | -1.411597 .2001829 -7.05 0.000 -1.803948 -1.019246 k618 | -.0815087 .0696247 -1.17 0.242 -.2179706 .0549531 age | .0659135 .1188199 0.55 0.579 -.1669693 .2987962 age2 | -.0014784 .0013584 -1.09 0.276 -.0041408 .001184 wc | .8098626 .2299065 3.52 0.000 .3592542 1.260471 hc | .1340998 .207023 0.65 0.517 -.2716579 .5398575 lwg | .5925741 .1507807 3.93 0.000 .2970495 .8880988 inc | -.0355964 .0083188 -4.28 0.000 -.0519009 -.0192919 _cons | .511489 2.527194 0.20 0.840 -4.44172 5.464698 ------------------------------------------------------------------------------ . . * use -praccum- without globals or forvalues . quietly prvalue, x(age 20 age2 400) rest(mean) . * the first call uses saving() . praccum, saving(mat_age) xis(20) . quietly prvalue, x(age 25 age2 625) rest(mean) . * remaining calls add to mat_age with the using() option . praccum, using(mat_age) xis(25) . quietly prvalue, x(age 30 age2 900) rest(mean) . praccum, using(mat_age) xis(30) . quietly prvalue, x(age 35 age2 1225) rest(mean) . praccum, using(mat_age) xis(35) . quietly prvalue, x(age 40 age2 1600) rest(mean) . praccum, using(mat_age) xis(40) . quietly prvalue, x(age 45 age2 2025) rest(mean) . praccum, using(mat_age) xis(45) . quietly prvalue, x(age 50 age2 2500) rest(mean) . praccum, using(mat_age) xis(50) . quietly prvalue, x(age 55 age2 3025) rest(mean) . praccum, using(mat_age) xis(55) . quietly prvalue, x(age 60 age2 3600) rest(mean) . * the last call of praccum generates agesqp1 and agesqx variables . praccum, using(mat_age) xis(60) gen(agesq) New variables created by praccum: Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- agesqx | 9 40 13.69306 20 60 agesqp0 | 9 .4282142 .1752595 .2676314 .7479599 agesqp1 | 9 .5717858 .1752595 .2520402 .7323686 . . * take a look at what was created . list agesqx agesqp0 agesqp1 in 1/10 +------------------------------+ | agesqx agesqp0 agesqp1 | |------------------------------| 1. | 20 .2676314 .7323686 | 2. | 25 .2682353 .7317647 | 3. | 30 .2836163 .7163837 | 4. | 35 .3152536 .6847464 | 5. | 40 .3656723 .6343277 | |------------------------------| 6. | 45 .4373158 .5626842 | 7. | 50 .5301194 .4698806 | 8. | 55 .6381241 .3618759 | 9. | 60 .7479599 .2520402 | 10. | . . . | +------------------------------+ . . * graph the results . label var agesqp1 "Pr(lpf | age,age2)" . label var agesqx "Age" . graph twoway connected pragep1 agesqp1 agesqx, /// > msymbol(Sh Dh) xlabel(20(5)60) /// > ytitle("Pr(Being in the Labor Force)") ylabel(0(.2)1) /// > ysize(2.7051) xsize(4.0421) . graph export 08lfp.eps, replace (file 08lfp.eps written in .eps format) . . // * section 8.4.2 - Using forvalues with praccum . * demonstration of forvalues . . forvalues count = 0(5)100 { 2. display `count' 3. } 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 . . * alternative method using forvalues and locals * . capture matrix drop mage . forvalues count = 20(5)60 { 2. local countsq = `count'^2 3. prvalue, x(age `count' age2 `countsq') rest(mean) brief 4. praccum, using(mage) xis(`count') 5. } Pr(y=inLF|x): 0.7324 95% ci: (0.3972,0.9191) Pr(y=NotInLF|x): 0.2676 95% ci: (0.0809,0.6028) Pr(y=inLF|x): 0.7318 95% ci: (0.5320,0.8675) Pr(y=NotInLF|x): 0.2682 95% ci: (0.1325,0.4680) Pr(y=inLF|x): 0.7164 95% ci: (0.6111,0.8024) Pr(y=NotInLF|x): 0.2836 95% ci: (0.1976,0.3889) Pr(y=inLF|x): 0.6847 95% ci: (0.6276,0.7368) Pr(y=NotInLF|x): 0.3153 95% ci: (0.2632,0.3724) Pr(y=inLF|x): 0.6343 95% ci: (0.5810,0.6846) Pr(y=NotInLF|x): 0.3657 95% ci: (0.3154,0.4190) Pr(y=inLF|x): 0.5627 95% ci: (0.5041,0.6196) Pr(y=NotInLF|x): 0.4373 95% ci: (0.3804,0.4959) Pr(y=inLF|x): 0.4699 95% ci: (0.4098,0.5308) Pr(y=NotInLF|x): 0.5301 95% ci: (0.4692,0.5902) Pr(y=inLF|x): 0.3619 95% ci: (0.2787,0.4543) Pr(y=NotInLF|x): 0.6381 95% ci: (0.5457,0.7213) Pr(y=inLF|x): 0.2520 95% ci: (0.1416,0.4078) Pr(y=NotInLF|x): 0.7480 95% ci: (0.5922,0.8584) . praccum, using(mage) gen(agsq) New variables created by praccum: Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- agsqx | 9 40 13.69306 20 60 agsqp0 | 9 .4282142 .1752595 .2676314 .7479599 agsqp1 | 9 .5717858 .1752595 .2520402 .7323686 . . // * section 8.4.3: Using praccum for graphing a transformed variable . . * estimate model with log age . gen ageln = ln(age) . logit lfp k5 k618 ageln wc hc lwg inc, nolog Logit estimates Number of obs = 753 LR chi2(7) = 122.95 Prob > chi2 = 0.0000 Log likelihood = -453.39788 Pseudo R2 = 0.1194 ------------------------------------------------------------------------------ lfp | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- k5 | -1.472077 .1998602 -7.37 0.000 -1.863796 -1.080359 k618 | -.0500888 .0671225 -0.75 0.456 -.1816465 .0814689 ageln | -2.577604 .5421115 -4.75 0.000 -3.640122 -1.515085 wc | .8058975 .229878 3.51 0.000 .3553449 1.25645 hc | .1049208 .2061561 0.51 0.611 -.2991377 .5089794 lwg | .6103714 .1509572 4.04 0.000 .3145008 .906242 inc | -.0340772 .0082012 -4.16 0.000 -.0501513 -.0180032 _cons | 10.09947 2.088741 4.84 0.000 6.005609 14.19332 ------------------------------------------------------------------------------ . . * using praccum and forvalues . capture matrix drop mat_ln . forvalues count = 20(5)60 { 2. local countln = ln(`count') 3. prvalue, x(ageln=`countln') rest(mean) brief 4. praccum, using(mat_ln) xis(`count') 5. } Pr(y=inLF|x): 0.9013 95% ci: (0.8025,0.9535) Pr(y=NotInLF|x): 0.0987 95% ci: (0.0465,0.1975) Pr(y=inLF|x): 0.8371 95% ci: (0.7423,0.9016) Pr(y=NotInLF|x): 0.1629 95% ci: (0.0984,0.2577) Pr(y=inLF|x): 0.7625 95% ci: (0.6837,0.8267) Pr(y=NotInLF|x): 0.2375 95% ci: (0.1733,0.3163) Pr(y=inLF|x): 0.6833 95% ci: (0.6260,0.7356) Pr(y=NotInLF|x): 0.3167 95% ci: (0.2644,0.3740) Pr(y=inLF|x): 0.6047 95% ci: (0.5639,0.6440) Pr(y=NotInLF|x): 0.3953 95% ci: (0.3560,0.4361) Pr(y=inLF|x): 0.5303 95% ci: (0.4874,0.5728) Pr(y=NotInLF|x): 0.4697 95% ci: (0.4272,0.5126) Pr(y=inLF|x): 0.4625 95% ci: (0.4039,0.5222) Pr(y=NotInLF|x): 0.5375 95% ci: (0.4778,0.5961) Pr(y=inLF|x): 0.4023 95% ci: (0.3278,0.4816) Pr(y=NotInLF|x): 0.5977 95% ci: (0.5184,0.6722) Pr(y=inLF|x): 0.3497 95% ci: (0.2640,0.4465) Pr(y=NotInLF|x): 0.6503 95% ci: (0.5535,0.7360) . praccum, using(mat_ln) gen(ageln) New variables created by praccum: Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- agelnx | 9 40 13.69306 20 60 agelnp0 | 9 .3851375 .1948801 .0987098 .6502514 agelnp1 | 9 .6148625 .1948802 .3497486 .9012902 . . label var agelnp1 "Pr(lpf | log of age)" . graph twoway connected pragep1 agesqp1 agelnp1 agesqx, /// > xlabel(20(5)60) msymbol(Sh Dh Th) /// > ytitle("Pr(Being in the Labor Force)") /// > ylabel(0(.2)1) ysize(2.7051) xsize(4.0421) . graph export 08lfp2.eps, replace (file 08lfp2.eps written in .eps format) . . // * section 8.4.4 - using praccum to graph interactions . . * estimate the model . use ordwarm2.dta, clear (77 & 89 General Social Survey) . gen maleXed = male*ed . ologit warm age prst yr89 white male ed maleXed, nolog Ordered logit estimates Number of obs = 2293 LR chi2(7) = 305.30 Prob > chi2 = 0.0000 Log likelihood = -2843.1198 Pseudo R2 = 0.0510 ------------------------------------------------------------------------------ warm | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | -.0212523 .0024775 -8.58 0.000 -.0261082 -.0163965 prst | .0052597 .0033198 1.58 0.113 -.001247 .0117664 yr89 | .5238686 .0799287 6.55 0.000 .3672111 .680526 white | -.3908743 .1184189 -3.30 0.001 -.622971 -.1587776 male | -.1505216 .3176105 -0.47 0.636 -.7730268 .4719836 ed | .0976341 .0226886 4.30 0.000 .0531651 .142103 maleXed | -.047534 .0251183 -1.89 0.058 -.0967649 .001697 -------------+---------------------------------------------------------------- _cut1 | -2.107903 .3043008 (Ancillary parameters) _cut2 | -.2761098 .2992857 _cut3 | 1.621787 .3018749 ------------------------------------------------------------------------------ . . * compute and accumulate predicted values for women . forvalues count = 8(2)20 { 2. quietly prvalue, x(male=0 ed=`count' maleXed=0) rest(mean) 3. praccum, using(mat_f) xis(`count') 4. } . praccum, using(mat_f) gen(pfem) New variables created by praccum: Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- pfemx | 7 14 4.320494 8 20 pfemp1 | 7 .0737801 .0283039 .0399257 .1183256 pfemp2 | 7 .2501559 .0622868 .1662394 .3376414 pfemp3 | 7 .425898 .0176338 .3923302 .4418006 pfemp4 | 7 .250166 .0775179 .1517029 .3659343 -------------+-------------------------------------------------------- pfems1 | 7 .0737801 .0283039 .0399257 .1183256 pfems2 | 7 .323936 .0904461 .2061651 .4559669 pfems3 | 7 .749834 .0775179 .6340657 .8482972 pfems4 | 7 1 0 1 1 . . * compute and accumulate predicted values for men . forvalues count = 8(2)20 { 2. quietly prvalue, x(male=1 ed=`count' maleXed=`count') rest(mean) 3. praccum, using(mat_m) xis(`count') 4. } . praccum, using(mat_m) gen(pmal) New variables created by praccum: Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- pmalx | 7 14 4.320494 8 20 pmalp1 | 7 .1462868 .0268927 .1111754 .1857918 pmalp2 | 7 .3669779 .0269781 .3273872 .4018448 pmalp3 | 7 .3607055 .0301248 .317195 .40045 pmalp4 | 7 .1260299 .0237202 .0951684 .1609874 -------------+-------------------------------------------------------- pmals1 | 7 .1462868 .0268927 .1111754 .1857918 pmals2 | 7 .5132647 .0537622 .4385626 .5876365 pmals3 | 7 .8739701 .0237202 .8390126 .9048315 pmals4 | 7 1 2.25e-08 .9999999 1 . . * graph the results . label var pfemp4 "Pr(SA | female)" . label var pmalp4 "Pr(SA | male)" . label var pfemx "Education in Years" . graph twoway connected pfemp4 pmalp4 pfemx, /// > msymbol(Sh Dh) xlabel(8(2)20) ylabel(0(.1).4) /// > ytitle("Pr(Strongly Agreeing)") /// > ysize(2.7051) xsize(4.0421) . graph export 08warm.eps, replace (file 08warm.eps written in .eps format) . . log close log: d:\spost.stata8\do\st8ch8.log log type: text closed on: 26 May 2003, 12:54:01 -------------------------------------------------------------------------------------------------------------