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]

From |
Steve Nakoneshny <scnakone@ucalgary.ca> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: proportional random sampling |

Date |
Wed, 26 Oct 2011 08:06:43 -0600 |

Thanks Stas. That will certainly work as well. As far as "elegant", my operational starting point is that the code that I write is relatively crude (even if functional) and that there is more than likely some means of streamlining or foreshortening the amount of code that I write / employ. While this certainly isn't always the case, it's nice to get feedback from others as well. Thanks, Steve On 2011-10-25, at 11:36 AM, Stas Kolenikov wrote: > 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 <scnakone@ucalgary.ca> 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: scnakone@ucalgary.ca >>>> To: statalist@hsphsun2.harvard.edu >>>> 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/ * * 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/

**References**:**st: proportional random sampling***From:*Steve Nakoneshny <scnakone@ucalgary.ca>

**RE: st: proportional random sampling***From:*Cameron McIntosh <cnm100@hotmail.com>

**Re: st: proportional random sampling***From:*Steve Nakoneshny <scnakone@ucalgary.ca>

**Re: st: proportional random sampling***From:*Stas Kolenikov <skolenik@gmail.com>

- Prev by Date:
**Re: st: beta regression** - Next by Date:
**st: RE: Hiding Variables** - Previous by thread:
**Re: st: proportional random sampling** - Next by thread:
**st: graph line, line(...)** - Index(es):