
From  "Sergiy Radyakin" <Radyakin@aoek.unihannover.de> 
To  <statalist@hsphsun2.harvard.edu> 
Subject  st: Re: FW: random number sequence within a loop 
Date  Mon, 5 Mar 2007 21:28:10 +0100 
Dear Stata users,
I'm trying to sample controls for a casecontrols study. For each case I
would like to sample one control. I use a loop for this, and "set seed"
to a random number. If I wouldn't do this then STATA will produce the
same random number sequence for each case within the loop, and the
control selection wouldn't be random. Therefore I have used:
.local seed = ceil(10000*uniform())
.set seed `seed'
to define the seed within the loop (see also below).This should ensure
that everytime stata goes through the loop, a different random number
sequence is generated (i hope this is correct). However, the problem is
that every time I run stata it will give me a different control for each
case. So, I can't reproduce my outcome. Is there any solution for this?
Thanks.
See my loop below:
forvalues i = 1/`case_num'{
local seed=ceil(10000*uniform())
set seed `seed'
gen random=uniform()
sort random
gen list = _n
replace control`i'=1 if list==`i'
}
Thanks
Raoul
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
* * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/
© Copyright 1996–2016 StataCorp LP  Terms of use  Privacy  Contact us  What's new  Site index 