. 
. * Program to draw 1 sample of size 30 from uniform ///
>   and return sample mean
. program onesample, rclass
  1.     version 11
  2.     drop _all
  3.     quietly set obs 30
  4.     generate x = runiform()
  5.     summarize x
  6.     return scalar meanforonesample = r(mean)
  7. end


. . * Run program onesample once as a check . set seed 10101

. onesample

Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- x | 30 .5459987 .2803788 .0524637 .9983786

. return list

scalars: r(meanforonesample) = .5459987225631873

. . * Run program onesample 10,000 times to get 10,000 sample means . simulate xbar = r(meanforonesample), seed(10101) /// > reps(10000) nodots: onesample

command: onesample xbar: r(meanforonesample)



. . * Summarize the 10,000 sample means and draw histogram . summarize xbar

Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- xbar | 10000 .4995835 .0533809 .3008736 .6990562

. histogram xbar, normal xtitle("xbar from many samples") (bin=40, start=.30087364, width=.00995456)

. . quietly graph export mus04fig1clt2.pdf, replace

.