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

Re: st: "random" seed for uniform()


From   Gary Longton <[email protected]>
To   [email protected]
Subject   Re: st: "random" seed for uniform()
Date   Thu, 09 Oct 2003 12:21:55 -0700

J. Michael Oakes wrote:

> Using Stata 8, I want to have a different seed each time I call an *.ado
> file with uniform() in it. I recall setting seed to 'system time' in SAS and
> in Stata... I think... and that worked well.
>
> Now I cannot recall how to set a new "random" seed and it's driving me nuts.
> I'm sure I'm missing something totally obvious but I cannot see outside of
> my box.

It is very possible that I am misunderstanding the intention of multiple calls to the ado file, so please disregard if the conditions described don't fit your situation.

*IF*
a) you are making calls to your ado file within a *single* Stata session (say within another ado or do file) and
b) you want to ensure "randomness" for the numbers generated between calls (eg. say the purpose of each call is to run a single simulations among multiple simulations - say to generate a random sample from some distribution and calculate the value of some statistic, and you will be repeating this call to the ado file to generate multiple random samples)

Then, I would argue against changing the seed at all.

1) there is no need
The seed does change each time a new random number is generated via the uniform() function according the recursion described in the [R]functions p.441 technical note (actually 4 different seeds corresponding to the 4 recursions of the KISS generator) and so will also change between calls to your ado-file within a session.

2) More importanly, the seeds will change in a manner which guarantees that the resulting overall sequence of uniform random numbers (which will continue between calls to your ado file) has the properties described for the generator.

By using a formula or a call to the system time to change the seed between calls or samples, you will in effect be creating your own random number generator with properties which are unknown and likely far inferior to those of the KISS generator (eg. the period will likely be shortened substantially).

- Gary



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