Let's save a sort order
gen order = _n
and let's tag one obs from each hh:
egen tag = tag(hhid)
Generate some nice randoms:
gen rnd = uniform()
And sort:
sort tag rnd
One observation per household has been
sorted to the end and those obs then shuffled.
Suppose as in your example you want 10 out
of 100 households
gen select = _n > (_N - 10)
-select- is 1 for the last 10 obs and 0 otherwise.
Now we spread the word among the hh members
bysort hhid (select) : replace select = select[_N]
and go back to the original sort order
sort order
In addition to the usual manual entries, see e.g.
http://www.stata.com/support/faqs/stat/sampling.html
Nick
[email protected]
--------------------------------------------------------------------------------
Marilyn Ibarra
Anyone know how to draw a random sample by hhid? I want to
draw a random sample at the household level, such that it
keeps everyone in the household. I would like a one percent
sample of households. So if I have 100 households but 500
individuals, I would like for it to keep 1 household (that
is all the members that belong to that 1 household).
My data looks like this.
Person hhid age
Luis 1 30
Nancy 1 35
Joe 1 32
Bren 2 15
Jane 2 9
Linda 3 11
Tom 3 65
*
* 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/