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

Re: st: problem with swor and by


From   Gabriel Demombynes <[email protected]>
To   [email protected]
Subject   Re: st: problem with swor and by
Date   Mon, 20 Dec 2004 07:05:47 -0800 (PST)

Oops, on closer consideration, I remembered that the
swor and by problem was in the 2nd stage of my two
2-stage sampling routine, so I can leave the first
swor statement (with no by) as is. 

For the second stage, I can replace

swor 10, by(cluster)

with

by cluster: sample 10, count

Thanks for the help! I'd still be interested to know
how one might handle the general problem of random
sampling with varying probabilities of selection.
Isn't this a common issue for survey design?

Gabriel


--- n j cox <[email protected]> wrote:

> -swor- was published in STB-59.
> I would have sworn that you don't
> now need it for your purpose,
> as -sample- has since been modified
> to support a -count- option.
> 
> However, I cannot reproduce your problem.
> I can get -swor- to select the same sample
> again and again.
> 
> . forval i = 1/10 {
>    2. qui sysuse auto, clear
>    3. set seed 28031952
>    4. qui swor 1, gen(select) by(foreign)
>    5. levels make, clean
>    6. }
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> Buick Riviera VW Rabbit
> 
> Try as I can, the Rabbit keeps coming
> out of the hat.
> 
> Nick
> [email protected]
> 
> Gabriel Demombynes wrote
> 
> I'm using the user-written command swor to draw
> random
> samples with
> replacement. I've discovered that even when I've set
> the seed, the
> command does not always draw the same samples in
> repeated runs when
> using by. It does not have this problem when not
> using
> by.
> 
> When I do the following, I get different results
> each
> time I run the
> program:
> 
> set seed 6662
> use alldata, clear
> swor 1, gen(select) by(sex)
> li
> 
> The problem seems to be particular to the variables
> in
> my dataset.
> When I create a new group variable, e.g. assigning
> group=1 for the
> first half of the observations, and group=2 for the
> second half, and
> then run the analysis by(group) there's no problem;
> I
> can reproduce the same results on multiple draws.
> But the problem
> persists even when I create a new group variable
> based
> on a pre-
> existing variable and use that, e.g.
> 
> set seed 6662
> use alldata, clear
> gen group=1 if sex==1
> replace group=2 if sex==2
> swor 1, gen(select) by(group)
> li
> 
> I've looked at the swor ado file, but I can't figure
> out what might be wrong. Any suggestions?
> *
> *   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/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
*
*   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