Statalist


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

Re: st: random sample selection


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: random sample selection
Date   Tue, 1 Apr 2008 09:19:53 -0400

How about:

set seed 12345
gen random = uniform()
sort random, stable
drop if id == 890800  //subject that wasn't suitable dropped
drop if _n>40

?

On Tue, Apr 1, 2008 at 8:38 AM, raoul reulen <r.c.reulen@gmail.com> wrote:
> Hi Statalisters,
>
>  I am trying to get a random sample of 40 subjects from a dataset of a
>  few hundred subject. This is what I did:
>
>  .set seed 12345
>  .gen random = uniform()
>  .sort random, stable
>  .drop if _n>40
>
>
>  For various reasons, it might be that some subjects in the sample are
>  not suitable for selection and I want to exclude them from the sample
>  and from the overall dataset.
>
>  So I selected another sample, however, when I did that other subjects
>  were selected as well.
>
>  .drop if id == 890800  //subject that wasn't suitable dropped
>  .set seed 12345
>  .gen random = uniform()
>  .sort random, stable
>  .drop if _n>40
>
>
>  What I want is to keep the original 39 subjects as in the old sample
>  in  and just replace the subject that wasn't suitable. Any suggestions
>  would be appreciated.
>
>  Many thanks.
>
>  Raoul
>
>
>
>
>  --
>  -------------------------------------------------------
>  Raoul C. Reulen
>  Cancer Research UK Training Fellow
>  *
>  *   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/
>
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index