* needs * ssc inst sparkline * ssc inst crossplot * ssc inst combineplot * ssc inst sepscatter * ssc inst aaplot * ssc inst designplot set scheme s1color * slides 11, 12, 13 webuse grunfeld, clear sparkline invest mvalue kstock year if company == 1, sub(company 1) more sparkline invest year, by(company) extremes more sparkline invest year, by(company) extremes extremeslabel ysc(r(0.3 3.7)) more clear input levels freqcores freqblanks freqtools 25 21 32 70 24 36 52 115 23 126 650 549 22 159 2342 1633 21 75 487 511 20 176 1090 912 19 132 713 578 18 46 374 266 17 550 6182 1541 16 76 846 349 15 17 182 51 14 4 51 14 13 29 228 130 12 135 2227 729 end foreach k in cores blanks tools { gen `k' = 100 * freq`k' / (freqcores + freqblanks + freqtools) } * slide 15 sparkline cores blanks tools levels, yaxis(1 2) vertical ysc(reverse) yla(12/25, axis(1) nogrid) format(%2.1f) recast(connected) ms(Oh Dh Th) plotregion(color(gs13)) xli(1.5 2.5, lw(*2) lstyle(grid)) yla(12/25, nogrid ang(h) axis(2)) flipy more clear input str3 month year y1 y2 y3 y4 y5 y6 y7 "Apr" 1854 8571 1 . 5 1.4 . 7 "May" 1854 23333 12 . 9 6.2 . 4.6 "Jun" 1854 28333 11 . 6 4.7 . 2.5 "Jul" 1854 28722 359 . 23 150 . 9.6 "Aug" 1854 30246 828 1 30 328.5 .4 11.9 "Sep" 1854 30290 788 81 70 312.2 32.1 27.7 "Oct" 1854 30643 503 132 128 197 51.7 50.1 "Nov" 1854 29736 844 287 106 340.6 115.8 42.8 "Dec" 1854 32779 1725 114 131 631.5 41.7 48 "Jan" 1855 32393 2761 83 324 1022.8 30.7 120 "Feb" 1855 30919 2120 42 361 822.8 16.3 140.1 "Mar" 1855 30107 1205 32 172 480.3 12.8 68.6 "Apr" 1855 32252 477 48 57 177.5 17.9 21.2 "May" 1855 35473 508 49 37 171.8 16.6 12.5 "Jun" 1855 38863 802 209 31 247.6 64.5 9.6 "Jul" 1855 42647 382 134 33 107.5 37.7 9.3 "Aug" 1855 44614 483 164 25 129.9 44.1 6.7 "Sep" 1855 47751 189 276 20 47.5 69.4 5 "Oct" 1855 46852 128 53 18 32.8 13.6 4.6 "Nov" 1855 37853 178 33 32 56.4 10.5 10.1 "Dec" 1855 43217 91 18 28 25.3 5 7.8 "Jan" 1856 44212 42 2 48 11.4 .5 13 "Feb" 1856 43485 24 . 19 6.6 . 5.2 "Mar" 1856 46140 15 . 35 3.9 . 9.1 end gen date = monthly(month + string(year), "MY") label var y5 "zymotic disease" label var y6 "wounds and injuries" label var y7 "all other causes" local d1 xla(-1255.5 "1855" -1267.5 "1854" -1247.5 "1856", noticks labsize(*1.2)) local d2 xli(-1261.5 -1249.5, lc(gs12)) local s "size(*1.2)" * slide 19 line y5 y6 y7 date, title(Nightingale's data on mortality in the Crimea) /// note(annualised rates per 1000) `d1' `d2' /// yla(0(200)1000, ang(h)) /// lp(solid dash solid) lc(red blue black) legend(col(1) ring(0) pos(1)) xtitle("") more qui forval j = 5/7 { clonevar sqrty`j' = y`j' replace sqrty`j' = sqrt(y`j') } * slide 20 line sqrty? date, title(Nightingale's data on mortality in the Crimea) /// note(annualised rates per 1000) `d1' `d2' /// yla(0 5 "25" 10 "100" 15 "225" 20 "400" 25 "625" 30 "900", ang(h)) /// lp(solid dash solid) lc(red blue black) legend(col(1) ring(0) pos(1)) xtitle("") more * slide 22 sparkline y5 y6 y7 date, title(Nightingale's data on mortality in the Crimea) /// note(annualised rates per 1000) `d1' `d2' variablelabels xtitle("") more use http://www.stata-press.com/data/r10/audiometric, clear * slide 30 crossplot (lft*) (rght*), jitter(1) more sysuse auto, clear gen rt_mpg = sqrt(mpg) gen ln_mpg = ln(mpg) gen rec_mpg = 100/mpg * slide 28 crossplot (mpg rt_mpg ln_mpg rec_mpg) weight, combine(imargin(small)) more * slide 36 combineplot mpg price weight headroom: graph box @y, over(rep78) more * slide 37 combineplot mpg price weight headroom: dotplot @y, over(rep78) more * slide 38 combineplot price mpg weight length: qnorm @y more * slide 39 combineplot (mpg price) (rep78 foreign), sequence(a b c d) seqopts(caption(, color(red))): graph box @y, over(@x) more * slide 40 combineplot price (mpg weight length displacement): sepscatter @y @x, ytitle("P rice (USD)") sep(foreign) more * slide 43 combineplot (weight length displacement) (weight length displacement), combine(imargin(vsmall)) : sepscatter @y @x, sep(foreign) legend(off) more * slide 44 combineplot price (mpg weight length displacement): aaplot @y @x, ytitle("Price (USD)") more * slide 52 designplot mpg rep78 more * slide 53 designplot mpg rep78 foreign more * slide 56 designplot mpg rep78 foreign, maxway(1) more * slide 63 grmeanby rep78 foreign, summarize(mpg) more * slide 66 designplot mpg foreign rep78, stat(min p25 median mean p75 max) maxway(1) legend(row(1)) more * slide 68 clonevar rep78_2 = rep78 replace rep78_2 = 6 if missing(rep78) * this works around a bug fixed in the next public version of -designplot- label def rep78_2 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "missing" label val rep78_2 rep78_2 designplot mpg for rep78_2, max(1) name(g1) designplot price for rep78_2, max(1) name(g2) designplot weight for rep78_2, max(1) name(g3) designplot weight for rep78_2, stat(count) max(1) name(g4) recast(hbar) t1title(counts) blabel(bar, size(medium)) graph combine g1 g2 g3 g4, imargin(small) more infix class 1-9 adult 10-18 male 19-27 survived 28-36 using http://www.amstat.org/publications/jse/datasets/titanic.dat.txt, clear label def class 0 crew 1 first 2 second 3 third label def adult 1 adult 0 child label def male 1 male 0 female label def survived 1 yes 2 no foreach v in class adult male survived { label val `v' `v' } * slide 58 designplot survived class adult male, max(2) ysize(7) more * slide 62 grmeanby class adult male, su(survived)