cd "/Users/kristenaiemjoy/Box Sync/_Teaching/Biostat 212/Biostat212.2017/Final Project" capture log close set linesize 152 quietly log using biostat212_FinalProjectExample.smcl, replace /*** #Biostat 212: 2017 #Example Final Project --- ***/ webuse nhanes2, clear /*** ##TABLE 1 Code ***/ label define diabetes_label 1 "Diabetics" 0 "Non diabetics" label values diabetes diabetes_label tabstat zinc copper vitaminc iron, by(diabetes) stat(n mean sd) save return list matrix list r(StatTotal) matrix stats1 = r(Stat1) matrix stats2 = r(Stat2) local d_n : display %9.0f stats2[1,1] local d_z : display %9.2f stats2[2,1] "("%9.1f stats2[3,1] ")" local d_c : display %9.2f stats2[2,2] "("%9.1f stats2[3,2] ")" local d_v : display %9.2f stats2[2,3] "("%9.1f stats2[3,3] ")" local d_i : display %9.2f stats2[2,4] "("%9.1f stats2[3,4] ")" local nd_n : display %9.0f stats1[1,1] local nd_z : display %9.2f stats1[2,1] "("%9.1f stats1[3,1] ")" local nd_c : display %9.2f stats1[2,2] "("%9.1f stats1[3,2] ")" local nd_v : display %9.2f stats1[2,3] "("%9.1f stats1[3,3] ")" local nd_i : display %9.2f stats1[2,4] "("%9.1f stats1[3,4] ")" /*** ##TABLE 1 ***/ tbl ("Mean (SD) ", "N", "Zinc", "Copper", "Vitamin C", "Iron" \ /// "_Diabetics_", `d_n', `d_z', `d_c', `d_v', `d_i' \ /// "_Non diabetics_", `nd_n', `nd_z', `nd_c', `nd_v', `nd_i') /// , title(Table 1: Serum Zinc, Copper, Vitamin C and Iron levels (mcg/DL) for Diabetics and Non-Diabetics in NHANES) /*** ##FIGURE 1 Code you will need to install 1 add-on package that combines legends called grc1leg net install grc1leg, from(http://www.stata.com/users/vwiggins) ***/ twoway /// kdensity zinc if diabetes==1 /// , lcolor(gray) || /// kdensity zinc if diabetes==0 /// , lcolor(black) lpattern(dash) /// , yscale(off) /// graphregion(color(white) lcolor(none) ilcolor(none)) /// legend(lab(1 "Diabetics") lab(2 "Non-diabetics")) /// ytitle("Density") xtitle("Serum Zinc (mcg/dL)") /// name(zinc_plot, replace) twoway /// kdensity copper if diabetes==1 /// , lcolor(gray) || /// kdensity copper if diabetes==0 /// , lcolor(black) lpattern(dash) /// , yscale(off) /// graphregion(color(white) lcolor(none) ilcolor(none)) /// legend(lab(1 "Non diabetics") lab(2 "Diabetics")) /// ytitle("Density") xtitle("Serum Copper (mcg/dL)") /// legend(off) /// name(copper_plot, replace) twoway /// kdensity vitaminc if diabetes==1 /// , lcolor(gray) || /// kdensity vitaminc if diabetes==0 /// , lcolor(black) lpattern(dash) /// , yscale(off) /// graphregion(color(white) lcolor(none) ilcolor(none)) /// legend(lab(1 "Non diabetics") lab(2 "Diabetics")) /// ytitle("Density") xtitle("Serum Vitamin C (mcg/dL)") /// legend(off) /// name(vc_plot, replace) twoway /// kdensity iron if diabetes==1 /// , lcolor(gray) || /// kdensity iron if diabetes==0 /// , lcolor(black) lpattern(dash) /// , yscale(off) /// graphregion(color(white) lcolor(none) ilcolor(none)) /// legend(lab(1 "Non diabetics") lab(2 "Diabetics")) /// ytitle("Density") xtitle("Serum Iron (mcg/dL)") /// legend(off) /// name(iron_plot, replace) grc1leg zinc_plot copper_plot vc_plot iron_plot /// , legendfrom(zinc_plot) /// title("Figure 1: K-density Distribution for Serum Zinc, Copper, Vitamin C" "and Iron levels in Diabetics and Non-diabetics") /// note("Data source: NHANES2") /*** ##FIGURE 1 ***/ img, w(900) h(900) markdoc biostat212_FinalProjectExample, replace statax export(pdf)