Figure 2.1, page 31.
use bigmice, clear graph twoway scatter weight day, msymbol(Oh)
Figure 2.2, page 32.
use bigmice, clear graph box weight, over(day) nooutsides
Figure 2.3, page 34.
use bigmice, clear xtline weight, addplot(scatter weight day, msymbol(Oh) legend(off)) /// i(id) t(day) overlay
Figure 2.6, page 41.
use bigmice, clear collapse (mean) mweight = weight (sd) sdweight =weight, by(day) graph twoway scatter mweight day, msymbol(Oh) name(f2_6a, replace) graph twoway scatter sdweight day, msymbol(Oh) name(f2_6b, replace) graph combine f2_6a f2_6b
Figure 2.7, page 42.
use pain, clear xtline paintol, i(id) t(trial) overlay xsize(2) legend(off) name(f2_7a, replace) xtline l2paintol, i(id) t(trial) overlay xsize(2) legend(off) name(f2_7b, replace) graph combine f2_7a f2_7b
Figure 2.9, page 45.
use pain, clear bysort id: gen obs = _N bysort id: egen maxpaintol = max(paintol) drop if obs !=4 | max ==240 collapse (mean) mpaintol = paintol ml2paintol=l2paintol /// (sd) sdpaintol = paintol sdl2paintol=l2paintol, by(id) graph twoway (lfit sdpaintol mpaintol) (scatter sdpaintol mpaintol, msymbol(Oh)), /// legend(off) xlabel(10(20)70) xtick(20(20)80) ylabel(0(20)60) name(f2_9a, replace) graph twoway (lfit sdl2paintol ml2paintol) (scatter sdl2paintol ml2paintol, msymbol(Oh)), /// legend(off) xlabel(3(1)6) ylabel(0.5 1 1.5) name(f2_9b, replace) graph combine f2_9a f2_9b, xsize(7)
Figure 2.10, page 46.
use pain, clear xtline l2paintol if cs=="attender", i(id) t(trial) legend(off) /// overlay name(f2_10a, replace) xtline l2paintol if cs=="distracter", i(id) t(trial) legend(off) /// overlay name(f2_10b, replace) graph combine f2_10a f2_10b
Table 2.1, page 48.
use ozonestations2, clear list +--------------------------------------------------------------+ | abbr long lat alt fullname | |--------------------------------------------------------------| 1. | RESE 118.533 34.199 226 RESEDA | 2. | BURK 118.308 34.183 168 BURBANK | 3. | SIMI 118.685 34.278 310 SIMI-VALLEY | 4. | PASA 118.127 34.134 250 PASADENA-WILSON | 5. | WSLA 118.455 34.051 91 WEST-LOS-ANGELES-VA-HOSPITAL | |--------------------------------------------------------------| 6. | HAWT 118.369 33.923 21 HAWTHORNE | 7. | LGBH 118.189 33.824 7 NORTH-LONG-BEACH | 8. | ANAH 117.919 33.821 41 ANAHEIM | 9. | CELA 118.225 34.067 87 LOS-ANGELES-NORTH-MAIN | 10. | AZUS 117.923 34.136 189 AZUSA | |--------------------------------------------------------------| 11. | POMA 117.751 34.067 270 POMONA | 12. | FONT 117.505 34.099 381 FONTANA-ARROW-HIGHWAY | 13. | SNBO 117.273 34.107 317 SAN-BERNARDINO | 14. | RIVR 117.417 34 214 RIVERSIDE-RUBIDOUX | 15. | UPLA 117.628 34.104 369 UPLAND-ARB | |--------------------------------------------------------------| 16. | CLAR 117.704 34.102 364 CLAREMONT-COLLEGE | 17. | LYNN 118.21 33.929 27 LYNWOOD | 18. | LAHB 117.951 33.926 82 LA-HABRA | 19. | WHIT 118.025 33.924 58 WHITTIER | 20. | PICO 118.058 34.015 69 PICO-RIVERA | +--------------------------------------------------------------+
Figure 2.11, page 49.
Note the x-axis in the text is reversed.
use newozone1, clear gen _long = long graph twoway scatter lat _long, mlabel(site) msymbol(i)
Figure 2.12, page 50.
use newozone1, clear graph twoway line ozone hour, connect(L) by(day, rows(1) compact note(" ")) /// sort(site day) legend(off) xlabel(8(2)18) ylabel(0(5)30)
Figure 2.13, page 51.
FINDIT LABMASK.
use newozone1, clear bysort site: egen maxozone = max(ozone) gsort - maxozone -site, gen(maxorder) labmask maxorder, values(site) graph twoway line ozone hour, connect(L) by(maxorder, rows(4) compact note(" ")) /// sort(maxorder day hour) legend(off) xlabel(8(2)18) ylabel(0(5)30)
Figure 2.14, page 52.
graph twoway line ozone hour if maxorder <=6, connect(L) /// by(maxorder day, rows(6) compact note(" ")) sort(maxorder day hour) xsize(3) /// legend(off) xlabel(8(2)18) ylabel(0(10)30)
Figure 2.15, page 53.
use weight1, clear graph twoway line weight week, connect(L) sort(id week) ylabel(140(20)260) /// xlabel(1(1)8) xsize(4.5)
Figure 2.16, page 54.
use weight1, clear graph twoway line weight week if weight <= 220, connect(L) sort(id week) /// xsize(3) xlabel(1(2)7) xtick(2(2)8) ylabel(140(20)200) name(f2_16a, replace) graph twoway line weight week if weight > 200, connect(L) sort(id week) /// xsize(3) xlabel(1(2)7) xtick(2(2)8) ylabel(200(20)260) name(f2_16b, replace) graph combine f2_16a f2_16b, xsize(3)
Figure 2.17, page 56.
use weight1, clear egen mweight = mean(weight), by(id) gen resid = weight-mweight graph twoway line resid week, connect(L) sort(id week) xlabel(1(1)8) /// ylabel(-10(5)10) name(f2_17, replace)
Figure 2.18, page 57.
use bigmice, clear egen mtweight = mean(weight), by(day) gen tresid = weight-mtweight xtline tresid, i(id) t(day) overlay xlabel(0(5)20) /// ylabel(-200(100)200) xsize(3.5) legend(off)
Table 2.2, page 58.
use pain, clear reshape wide paintol l2paintol, i(id) j(trial) corr l2paint* (obs=58) | l2pain~1 l2pain~2 l2pain~3 l2pain~4 -------------+------------------------------------ l2paintol1 | 1.0000 l2paintol2 | 0.7302 1.0000 l2paintol3 | 0.8363 0.7177 1.0000 l2paintol4 | 0.6112 0.6612 0.7642 1.0000
Table 2.3, page 59.
use smallmice, clear reshape wide weight, i(id) j(day) corr weight* (obs=14) | weight2 weight5 weight8 weight11 weight14 weight17 weight20 -------------+--------------------------------------------------------------- weight2 | 1.0000 weight5 | 0.9236 1.0000 weight8 | 0.5665 0.7728 1.0000 weight11 | 0.3613 0.5356 0.8639 1.0000 weight14 | 0.2310 0.4500 0.8008 0.9278 1.0000 weight17 | 0.2313 0.4093 0.7579 0.9162 0.9554 1.0000 weight20 | 0.3845 0.5473 0.8091 0.8674 0.8888 0.9224 1.0000
Table 2.4, page 60.
ERROR: RESULTS DO NOT MATCH EXACTLY.
use newozone1, clear keep site hour ozone day reshape wide ozone, i(site day) j(hour) corr ozone* (obs=59) | ozone7 ozone8 ozone9 ozone10 ozone11 ozone12 ozone13 ozone14 ozone15 ozone16 ozone17 ozone18 -------------+------------------------------------------------------------------------------------------------------------ ozone7 | 1.0000 ozone8 | 0.2783 1.0000 ozone9 | -0.0159 0.5279 1.0000 ozone10 | -0.1632 0.3290 0.7487 1.0000 ozone11 | -0.2273 0.0266 0.4858 0.7927 1.0000 ozone12 | -0.2556 -0.1035 0.3213 0.5894 0.8628 1.0000 ozone13 | -0.2551 -0.1001 0.2408 0.3916 0.5972 0.8296 1.0000 ozone14 | -0.2586 -0.1915 0.2117 0.2447 0.4441 0.6932 0.8917 1.0000 ozone15 | -0.2982 -0.1978 0.2872 0.3256 0.5026 0.6812 0.8115 0.9348 1.0000 ozone16 | -0.2927 -0.1276 0.3746 0.3634 0.4868 0.6421 0.7313 0.8537 0.9255 1.0000 ozone17 | -0.2517 -0.0686 0.3843 0.3721 0.5066 0.5888 0.6197 0.7662 0.8380 0.9079 1.0000 ozone18 | -0.2348 0.0264 0.4722 0.4710 0.5359 0.5132 0.5007 0.6277 0.7517 0.8083 0.9311 1.0000 corr ozone*, covariance (obs=59) | ozone7 ozone8 ozone9 ozone10 ozone11 ozone12 ozone13 ozone14 ozone15 ozone16 ozone17 ozone18 -------------+------------------------------------------------------------------------------------------------------------ ozone7 | .394605 ozone8 | .129378 .547627 ozone9 | -.014506 .56635 2.10179 ozone10 | -.193352 .459129 2.04661 3.55548 ozone11 | -.347887 .047943 1.71573 3.64143 5.93454 ozone12 | -.527247 -.251473 1.52967 3.64963 6.90234 10.7841 ozone13 | -.659071 -.304614 1.43618 3.03689 5.98398 11.2061 16.9194 ozone14 | -.87232 -.760745 1.648 2.47754 5.80932 12.2223 19.6939 28.8304 ozone15 | -1.13846 -.889717 2.53056 3.73096 7.4405 13.5963 20.2863 30.5067 36.9366 ozone16 | -1.0781 -.553574 3.18361 4.0176 6.95176 12.3621 17.6349 26.8728 32.9779 34.3708 ozone17 | -.803685 -.258098 2.8314 3.56571 6.27175 9.82738 12.955 20.9091 25.8845 27.051 25.8298 ozone18 | -.58486 .077589 2.71389 3.52122 5.17613 6.68231 8.16621 13.3629 18.1123 18.7878 18.7619 15.7187
Figure 2.19, page 62.
use pain, clear reshape wide paintol l2paintol, i(id) j(trial) graph matrix l2pain*, msymbol(Oh)
Figure 2.20, page 64.
use smallmice, clear reshape wide weight, i(id) j(day) graph matrix weight*, msymbol(Oh)
Figure 2.23, page 68.
use bigmice, clear egen sdweight = sd(weight), by(day) bysort day: gen sdmweight = sdweight/sqrt(_N) egen mweight = mean(weight), by(day) serrbar mweight sdmweight day, addplot(line mweight day, sort) /// legend(off) scale(2) ylabel(200(400)1000) ytick(400(400)1200) msize(vlarge) /// xsize(4) name(f2_23a, replace) serrbar mweight sdweight day, addplot(line mweight day, sort) /// legend(off) scale(2) ylabel(200(400)1000) ytick(400(400)1200) msize(vlarge) /// xsize(4) name(f2_23b, replace) graph combine f2_23a f2_23b, xsize(7)
Figure 2.24, page 69.
Right side graph only.
use pain, clear collapse (sd) sdl2pain = l2paintol (mean) ml2pain = l2paintol (count) freq = id, /// by(trial cs) gen lsdm2l2 = ml2pain-2*sdl2pain/sqrt(freq) gen usdm2l2 = ml2pain+2*sdl2pain/sqrt(freq) replace trial = trial + .1 if cs == "distracter" graph twoway (line ml2pain trial if cs == "attender", lcolor(navy)) /// (rcap lsdm2l2 usdm2l2 trial if cs == "attender", msize(vlarge) lcolor(navy)) /// (line ml2pain trial if cs == "distracter", lcolor(orange)) /// (rcap lsdm2l2 usdm2l2 trial if cs == "distracter", msize(vlarge) lcolor(orange)), /// legend(off) ylabel(4.2(.4)5.4)
Table 2.7, page 70.
ERROR: NUMBERS DO NOT MATCH EXACTLY.
use cognitive, clear tab rn if ravens !=. rn | Freq. Percent Cum. ------------+----------------------------------- 1 | 537 20.67 20.67 2 | 529 20.36 41.03 3 | 523 20.13 61.16 4 | 513 19.75 80.91 5 | 496 19.09 100.00 ------------+----------------------------------- Total | 2,598 100.00
Table 2.8, page 70.
ERROR: RESULTS DO NOT MATCH.
use cognitive, clear collapse (sum) ravensobs, by(id) tab ravensobs (sum) | ravensobs | Freq. Percent Cum. ------------+----------------------------------- 1 | 6 1.10 1.10 2 | 14 2.56 3.66 3 | 15 2.75 6.41 4 | 36 6.59 13.00 5 | 475 87.00 100.00 ------------+----------------------------------- Total | 546 100.00
Figure 2.25, page 71.
?ERROR: RESULTS MAY NOT MATCH.
use cognitive, clear histogram relmonth, frequency xlabel(0(5)25) bin(50)
Figure 2.26, page 72.
ERROR: GRAPH DOES NOT MATCH.
use cognitive, clear scatter id relmonth if id <=80, msymbol(Sh) xlabel(0(5)20) xline(0 3) /// xsize(3) ysize(5) ytick(1(1)80)