Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: proportional random sampling


From   Steve Nakoneshny <scnakone@ucalgary.ca>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: proportional random sampling
Date   Mon, 24 Oct 2011 17:15:20 -0600

Dear Statalisters,

I have a small dataset (n=44) from which I want to draw a random sample of records. The distribution of these records across my variable of interest in approximately 2:1. What I wish to do is to create a random sample of records of size n that retains the proportional distribution across my variable of interest.

Assuming a random sample where n=12, I wrote the following code:

sort ecs
by ecs: sample 8,count
sample 50 if ecs==1

------
Although how I coded it certainly works, what I am wondering if there is a more elegant means of coding to achieve a similar result?


Thanks,
Steve
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index