Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • seed number for randomly sampled multiple subgroups

    I need to take a random sample from five different groups. Should I set the seed once, or should I set seeds five times for five subgroups?

    Here is my code:
    set seed 123456
    sample 1 if race_single==1 & hispanic==0
    set seed 124312
    sample 10 if race_single==1 & hispanic==1
    set seed 654321
    sample 10 if race_single==2 & hispanic==0
    set seed 345678
    sample 10 if race_single==6 & hispanic==0
    set seed 234567
    sample 10 if race_single==6 & hispanic==1

    Is this code giving me what I am supposed to get?

  • #2
    There is no need to set the seed separately for these. The Stata random number generator, whether you are using the current version of Stata or an earlier version, will produce independent random samples after just a single -set seed- command. That is what you need.

    Is there any harm to setting separate seeds? There may be. For Stata version 14 and later, the default random number generator is Mersenne Twister. I have read, although I cannot find the reference just now, that if you have two streams of numbers coming out of Mersenne Twister started with two different seeds, there may actually be some dependency between the corresponding outputs in the streams, depending on the particular seeds used. By contrast, Mersenne Twister produces a long stream of independent random numbers starting from a single seed (until it approaches the end of its cycle--which will be some time around when the sun expands to swallow the earth ).

    Comment

    Working...
    X