************************************************************************************ *** This program samples observations from FILEPATH and returns the mean and count *** of VAR for REPNUM samples of size SAMPSIZE ************************************************************************************ *** FILEPATH *** use "E:\Course\Datasets\EMS\perulung_ems.dta", clear *** Program definition *** capture program drop mymean program define mymean, rclass syntax [varname] *** FILEPATH *** use "E:\Course\Datasets\EMS\perulung_ems.dta", clear *** SAMPSIZE *** sample 10, count return local varname 'varlist' quietly { *** VAR *** summarize fev1 return scalar mean = r(mean) return scalar N = r(N) } end *** Start simulation *** simulate "mymean fev1" mean=r(mean) N=r(N), reps(100) dots *** Summarize simulation results *** label variable mean "Mean Forced Expiratory Volume (liters)" label variable N "Number of observations drawn for each sampling replication" histogram mean, frequency ylabel(2(2)20) xlabel(1.2(.1)2) /// ytitle(, margin(small)) xtitle(, alignment(middle) margin(medsmall)) /// title(Samping Variation) normal summarize mean, detail ************************************************************************************