. webuse nhanes2, clear
. 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
Summary statistics: N, mean, sd
by categories of: diabetes (diabetes, 1=yes, 0=no)
diabetes | zinc copper vitaminc iron
--------------+----------------------------------------
Non diabetics | 8750 8679 9486 9850
| 86.65074 125.3898 1.032933 99.85706
| 14.49493 32.72976 .5774621 34.14416
--------------+----------------------------------------
Diabetics | 451 450 485 499
| 83.69845 130.04 1.072784 91.34269
| 13.8738 27.80633 .6534093 31.77103
--------------+----------------------------------------
Total | 9201 9129 9971 10349
| 86.50603 125.619 1.034871 99.44652
| 14.47842 32.51881 .5814126 34.08093
-------------------------------------------------------
. return list
macros:
r(name2) : "Diabetics"
r(name1) : "Non diabetics"
matrices:
r(Stat2) : 3 x 4
r(Stat1) : 3 x 4
r(StatTotal) : 3 x 4
. matrix list r(StatTotal)
r(StatTotal)[3,4]
zinc copper vitaminc iron
N 9201 9129 9971 10349
mean 86.506032 125.61902 1.0348711 99.446517
sd 14.478417 32.518809 .58141263 34.080933
. 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: Serum Zinc, Copper, Vitamin C and Iron levels (mcg/DL) for Diabetics and Non-Diabetics in NHANES
| Mean (SD) | N | Zinc | Copper | Vitamin C | Iron |
|---|---|---|---|---|---|
| Diabetics | 451 | 83.70( 13.9) | 130.04( 27.8) | 1.07( 0.7) | 91.34( 31.8) |
| Non diabetics | 8750 | 86.65( 14.5) | 125.39( 32.7) | 1.03( 0.6) | 99.86( 34.1) |
Table 1: Serum Zinc, Copper, Vitamin C and Iron levels (mcg/DL) for Diabetics and Non-Diabetics in NHANES
| _______ | Diabetics | Non diabetics |
|---|---|---|
| ________ | 451 | 8750 |
| Zinc | 83.70( 13.9) | 86.65( 14.5) |
| Copper | 130.04( 27.8) | 125.39( 32.7) |
| Vitamin C | 1.07( 0.7) | 1.03( 0.6) |
| Iron | 1.07( 0.7) | 1.03( 0.6) |
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") region(style(none))) ///
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)) ///
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)) ///
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)) ///
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) ///
subtitle("Figure 1: K-density Distribution for Serum Zinc, Copper, Vitamin C" "and Iron levels in Diabetics and Non-diabetics") ///
note("Data source: NHANES2") ///
scheme(s1mono)
The linesize option is discontinued. markdoc auto-detects the linesize...