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, is already up and running.

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

st: proportional random sampling

From   Steve Nakoneshny <>
To   "" <>
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?

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index