Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: proportional random sampling


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: proportional random sampling
Date   Tue, 25 Oct 2011 12:36:08 -0500

It looks like

sample 27, by( ecs )

would likely achieve what you need (where 27% = 12/44). Define
"elegant" first so that we know what you are looking for :).

If you want an absolutely full control over what's going on, you can do this:

set seed 20111025
tempvar r sample
generate `r' = uniform()
generate byte `sample' = 1
bysort ecs (`r') : replace `sample' = 0 if _n > 8 & ecs == "larger group"
bysort ecs (`r') : replace `sample' = 0 if _n > 4 & ecs == "smaller group"

count if `sample'
assert r(N) == 12

keep if `sample'
drop `r' `sample'

On Tue, Oct 25, 2011 at 12:05 PM, Steve Nakoneshny <[email protected]> wrote:
> Hi Cam,
>
> We're investigating in a retrospective study whether or not a particular pathologic feature of a tumour can be accurately predicted using an imaging modality (CT scan) prior to surgery. We've identified 44 eligible patients for which the distribution of this feature is approximately 2:1. Prior to undertaking the majority of the work, it was suggested that we take a random sample of each group (positive and negative) and ask the radiologists to asses their scans blindly in order to validate the data collection instrument as a pilot test.
>
> The plan was to go with 5 from each arm, but it was later suggested that we provide them with an unequal distribution so that the radiologists don't automatically assume a 50/50 split. I could easily go with a fully randomized selection, but I want to ensure that we have a representative proportion for each, hence wanting to retain the 2:1 ratio.
>
> I have already narrowed down the dataset to a random sample I'm comfortable with via the code I employed previously. I was simply asking of the list if anyone could suggest an alternate means of arriving at a similar result in perhaps a more elegant fashion as a purely intellectual exercise. If not, that's fine too.
>
> Thanks,
> Steve
>
> On 2011-10-24, at 8:51 PM, Cameron McIntosh wrote:
>
>> Steve,
>> I think that if you described the motivation for this exercise, it might help elicit advice -- perhaps some that even suggests an alternative way of looking at your problem, whatever that may be. :)
>> Thanks,
>> Cam
>>
>> ----------------------------------------
>>> From: [email protected]
>>> To: [email protected]
>>> Date: Mon, 24 Oct 2011 17:15:20 -0600
>>> Subject: st: proportional random sampling
>>>
>>> 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/
>>
>> *
>> *   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/
>
>
> *
> *   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/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index