use "H:\Work files\Teaching\Biostat 200 -- 2013\biostat200_2013_v1.dta", clear hist age, normal percent fcolor(blue) normopts(lcolor(magenta) lwidth(medthick)) title(Age in entire population) name(hist_a1, replace) keep age sample 100, count rename age age1 save "H:\Work files\Teaching\Biostat 200 -- 2013\age samples.dta",replace use "H:\Work files\Teaching\Biostat 200 -- 2013\biostat200_2013_v1.dta", clear keep age sample 100, count rename age age2 merge 1:1 _n using "H:\Work files\Teaching\Biostat 200 -- 2013\age samples.dta" drop _merge sleep 100 save "H:\Work files\Teaching\Biostat 200 -- 2013\age samples.dta",replace forvalues i=3/20 { use "H:\Work files\Teaching\Biostat 200 -- 2013\biostat200_2013_v1.dta", clear keep age sample 100, count rename age age`i' merge 1:1 _n using "H:\Work files\Teaching\Biostat 200 -- 2013\age samples.dta" drop _merge sleep 100 save "H:\Work files\Teaching\Biostat 200 -- 2013\age samples.dta",replace } order *, sequential save "H:\Work files\Teaching\Biostat 200 -- 2013\age samples.dta",replace histogram age1, xlabel(20(20)80) percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Mean ages for samples with n=1, size(small)) name(hist_as1, replace) egen agem2=rowmean(age1-age2) summ agem2, detail histogram agem2, xlabel(20(20)80) percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Mean ages for samples with n=2, size(small)) name(hist_as2, replace) egen agem5=rowmean(age1-age5) summ agem5, detail histogram agem5, xlabel(20(20)80) percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Mean ages for samples with n=5, size(small)) name(hist_as5, replace) egen agem10=rowmean(age1-age10) summ agem10, detail histogram agem10, xlabel(20(20)80) percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Mean ages for samples with n=10, size(small)) name(hist_as10, replace) egen agem20=rowmean(age1-age20) summ agem20, detail histogram agem20, xlabel(20(20)80) percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Mean ages for samples with n=20, size(small)) name(hist_as20, replace) egen agem30=rowmean(age1-age30) summ agem30, detail histogram agem30, xlabel(20(20)80) percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Mean ages for samples with n=30, size(small)) name(hist_as30, replace) graph combine hist_a1 hist_as1 hist_as2 hist_as5 hist_as10 hist_as30 , name(agehists,replace)