Some days ago, the following issue concerning -gsample- was posted by
Shige on behalf of a colleague:
I am trying to draw a PPS sample using the "gsample" command. I want
to make sure I get the same sample each time I invoke the gsample
command by using the "set seed" command. However, even after I set the
random seed using "set seed" command, I still get different sample
each time. Has anybody encountered this problem?
Inspection of Shige's colleague's do-file revealed that some -sort-
and -bysort- commands were causing the trouble. It had nothing to do
with -gsample-. -sort- has its own random number generator to break
ties that does not depend on -set seed-. To make -sort- stable either
specify the -stable- option or, better, add a -set sortseed- command
at the beginning of the script (see -help sortseed-).
Nick wrote:
You must -set seed- immediately before calling -gsample-.
No. The seed should be set somewhere in the beginning of the do-file,
before any command that might possibly depend on it (and it should
only be set once - do not set the seed repeatedly in one script).
ben
*
* 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/