Hi,
I'm trying to generate 200 samples of n=100, 200 and 400 normally distributed observations, average them by sample and see I should reject them. The code below works but is taking a very long time (6-7 hours so far and not even completed n=100). I was wondering if there is any faster way to do it, while following the instructions above?
Thanks
I'm trying to generate 200 samples of n=100, 200 and 400 normally distributed observations, average them by sample and see I should reject them. The code below works but is taking a very long time (6-7 hours so far and not even completed n=100). I was wondering if there is any faster way to do it, while following the instructions above?
Thanks
Code:
clear all local j=0 foreach sample_size of numlist 100 200 400 { forvalues theta=-1(0.01)3 { local seed 20211217+1000*`theta' quietly { forvalues i=1/200 { clear all set obs `sample_size' local new_seed=`seed'+`i' set seed `new_seed' gen double theta=round(`theta', 0.01) gen obs=rnormal(1+`theta'/sqrt(`sample_size'), 1) display `j' if `j'==0 { capture erase normal_R200_n`sample_size'_2.dta } local ++j * Test gen test=obs>invnormal(0.95)+sqrt(`sample_size')*(`theta0'-theta) if `j'>1 { append using "normal_R200_n`sample_size'_2" } save "normal_R200_n`sample_size'_2", replace } } } * Average rejection rate by R samples collapse (mean) average_rejection=test, by(theta) la var average_rejection "Rejection rate" la var theta "{&theta}" graph twoway scatter average_rejection theta, /// msize(tiny) yline(0.05, lcolor(red)) /// ylabel(0 "0" 0.05 "{&alpha}" 1 "1", angle(0)) graph export "Q2e_rejection_prob_by_theta_n`sample_size'.png", replace save "normal_R200_n`sample_size'_collapsed_2", replace }
Comment