Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: reproducibility of rndbin - set seed


From   david schriger <schriger@ucla.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: reproducibility of rndbin - set seed
Date   Fri, 26 Mar 2004 22:32:57 +0000

Dear StataListers,

The following .do file produces different results for xb each time run.

clear
set seed 4530754024
rndbin 10000 .363328 262
summ xb, d


Since the rndbin command invokes uniform() I thought that setting the seed would make the program produce identical results.
What am I missing? Did seed not exist in version 3.1?

here is the relevant snipped of the binreg .ado file

program define rndbin
version 3.1
cap drop xb
qui {
local cases `1'
set obs `cases'
mac shift
local pp `1'
mac shift
local n `1'
if `pp' < 0.5 { local p = `pp' }
else { local p = 1.0 - `pp' }
local am = `n'*`p'
noi di in gr "( Generating " _c
....
....
....
tempvar ran1 ran2 ds ts sum1 e y em bn1
local en = `n'
local oldg = lngamma(`en'+1.0)
local pc=1.0-`p'
local plog = log(`p')
local pclog = log(`pc')
local sq = sqrt(2.0*`am'*`pc')
gen `em' = -1
gen `e' = -1
gen `ran1' = uniform()
gen `ran2' = uniform()
gen `ds' = 1
gen `ts' = 1
gen `y' = -1
egen `sum1' = sum(`ds')
while `sum1' > 0 {
replace `y' = sin(_pi*`ran1')/cos(_pi*`ran1')
replace `em' = `sq'*`y' + `am' if (`ds'==1)
replace `ts' =0 if (((0>`em') | (`em' >=(`en'+1.0))) & (`ds'==1))
#delimit ;
replace `e' = 1.2*`sq'*(1.0+(`y'*`y'))*exp(`oldg'-lngamma(`em'+1.0)
-lngamma(`en'-`em'+1.0) + (`em' *`plog')+(`en'-`em')*`pclog') if
(( `ds'==1) & (`ts'==1));
#delimit cr
replace `ds'=0 if ((`ran2'<`e') & (`ds'==1) & (`ts'==1))
replace `ran1' = uniform()
replace `ran2' = uniform()
replace `e'=-1
replace `ts' = 1
drop `sum1'
egen `sum1' = sum(`ds')
noi di in gr "." _c
}


Thanks for the insight.

David Schriger
Emergency Medicine Center, UCLA

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index