*** this prgram takes samples of varying sizes from known distributions to demonstrate the central limit theorem *** clear ** 1000 obs to have the repeated drawing of samples *** set obs 1000 *** generate 50 columns of data, to be used in varying n's i.e. 1,2,5,10,20,50 to calculate means *** *** this one is using the uniform distribution as the underlying distribution ** *** forvalues i=1/50 { gen unif`i'=runiform() } *** note that the above code is the same as writing out the following *** *** gen unif1=runiform() *** gen unif2=runiform() *** gen unif3=runiform() *** gen unif4=runiform() *** gen unif5=runiform() *** gen unif6=runiform() *** etc. *** etc. *** etc. *** gen unif49=runiform() *** gen unif50=runiform() ** repeated samples with n=1 in each sample** gen m1=unif1 histogram m1, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 1, size(small)) name(hist_unif_1, replace) ** repeated samples with n=2 in each sample ** egen m2=rowmean(unif1-unif2) histogram m2, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 2 from uniform dist , size(small)) name(hist_unif_2, replace) ** repeated samples with n=5 in each sample ** egen m5=rowmean(unif1-unif5) histogram m5, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 5 from uniform dist, size(small)) name(hist_unif_5, replace) ** repeated samples with n=10 in each sample ** egen m10=rowmean(unif1-unif10) histogram m10, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 10 from uniform dist, size(small)) name(hist_unif_10, replace) ** repeated samples with n=20 in each sample ** egen m20=rowmean(unif1-unif20) histogram m20, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 20 from uniform dist, size(small)) name(hist_unif_20, replace) ** repeated samples with n=50 in each sample ** egen m50=rowmean(unif1-unif50) histogram m50, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 50 from uniform dist, size(small)) name(hist_unif_50, replace) graph combine hist_unif_1 hist_unif_2 hist_unif_5 hist_unif_10 hist_unif_20 hist_unif_50, name(unifgraphs, replace) ** now using the chi square distribution *** clear set obs 1000 forvalues i=1/50 { gen chisq`i'=rchi2(1) } summ chisq1, detail ** repeated samples with n=1 in each sample ** hist chisq1, normal histogram chisq1, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 1 from Chi-square dist, size(small)) name(hist_ch1, replace) ** repeated samples with n=2 in each sample ** egen ch2=rowmean(chisq1-chisq2) summ ch2, detail histogram ch2, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 2 from Chi-square dist, size(small)) name(hist_ch2, replace) ** repeated samples with n=5 in each sample** egen ch5=rowmean(chisq1-chisq5) histogram ch5, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 5 from Chi-square dist, size(small)) name(hist_ch5, replace) ** repeated samples with n=10 in each sample** egen ch10=rowmean(chisq1-chisq10) summ ch10, detail histogram ch10, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 10 from Chi-square dist, size(small)) name(hist_ch10, replace) ** repeated samples with n=20 in each sample** egen ch20=rowmean(chisq1-chisq20) histogram ch20, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 20 from Chi-square dist, size(small)) name(hist_ch20, replace) ** repeated samples with n=50 in each sample** egen ch50=rowmean(chisq1-chisq50) histogram ch50, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 50 from Chi-square dist, size(small)) name(hist_ch50, replace) graph combine hist_ch1 hist_ch2 hist_ch5 hist_ch10 hist_ch20 hist_ch50 , name(chihists,replace) ** now using the poisson distribution, with lambda=1.5 *** clear set obs 1000 forvalues i=1/50 { gen poiss`i'=rpoisson(1.5) } ** repeated samples with n=1 in each sample ** histogram poiss1, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 1 from Poisson dist, size(small)) name(hist_pois1, replace) ** repeated samples with n=2 in each sample ** egen p2=rowmean(poiss1-poiss2) summ p2, detail histogram p2, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 2 from Poisson dist, size(small)) name(hist_pois2, replace) ** repeated samples with n=5 in each sample** egen p5=rowmean(poiss1-poiss5) histogram p5, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 5 from Poisson dist, size(small)) name(hist_pois5, replace) ** repeated samples with n=10 in each sample** egen p10=rowmean(poiss1-poiss10) histogram p10, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 10 from Poisson dist, size(small)) name(hist_pois10, replace) ** repeated samples with n=20 in each sample** egen p20=rowmean(poiss1-poiss20) histogram p20, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 20 from Poisson dist, size(small)) name(hist_pois20, replace) ** repeated samples with n=50 in each sample** egen p50=rowmean(poiss1-poiss50) histogram p50, percent fcolor(blue) normal normopts(lcolor(magenta) lwidth(medthick)) title(Means of samples of size 50 from Poisson dist, size(small)) name(hist_pois50, replace) graph combine hist_pois1 hist_pois2 hist_pois5 hist_pois10 hist_pois20 hist_pois50 , name(poishists,replace)