Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: set seed and gsample

From   "Ben Jann" <>
Subject   Re: st: set seed and gsample
Date   Sat, 10 Mar 2007 23:55:35 +0100

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).

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index