Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: sampling by id, was Re: statalist-digest V4 #1555


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: sampling by id, was Re: statalist-digest V4 #1555
Date   Sun, 21 Mar 2004 09:35:45 -0500

One approach (assuming that your data "mydata.dta" is already sorted by id):

use mydata
keep id
bysort id: keep if _n==1
sample 5
sort id
merge id using mydata, nokeep
drop _merge
save mysample


Michael Blasnik
[email protected]

----- Original Message ----- 
From: "Carlos Elordi" <[email protected]>
To: <[email protected]>
Sent: Saturday, March 20, 2004 4:57 PM
Subject: st: Re: statalist-digest V4 #1555


> Hi,
> I would like to create a random sample of observations from a large data
> file (lets say 1 or 5%), selecting cases based on an id number. For many
> cases I have more than one row (record) per id number, so I cannot apply
the
> sample command directly.
> Is there an easy way to randomly select all the cases, together with their
> corresponding records, without having to reshape the data? The number of
> records for each case could range from 1 to 15.
> Thanks in advance for any help,
> Carlos
>
>
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index