| ![]() |
||||
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: counting number of children in a household
From
"Michael Blasnik" <michael.blasnik@verizon.net>
To
<statalist@hsphsun2.harvard.edu>
Subject
Re: st: counting number of children in a household
Date
Tue, 28 Feb 2006 19:21:01 -0500
Your approach involves a lot of unnecessary work -- 5 lines of code with two
egen calls -- when it can be done more quickly from first principles:
bysort hhid: gen no_childr=sum(age<19)
by hhid: replace no_childr=no_childr[_N]
Michael Blasnik
michael.blasnik@verizon.net
----- Original Message -----
From: "Zamira Simkins" <zs9814a@american.edu>
To: <statalist@hsphsun2.harvard.edu>
Sent: Tuesday, February 28, 2006 7:01 PM
Subject: RE: st: counting number of children in a household
Someone asked how to count how many children are in a given household and
how to assign this number to each individual in the same household.
What I usually do is:
sort hhid
egen no_kids=count(id) if age<19, by(hhid)
/*this counts kids in every hh and places the sum in a row where an
individual is <=18yo, rows with adults will have a missing value because
they did not meet the if condition*/
egen no_childr=max(no_kids), by(hhid)
/*this assigns the total number of children to each individual within the
same hh*/
replace no_childr=0 if no_childr==.
drop no_kids
/*you do not need no_kids anymore, so drop it*/
*
* 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–2008 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |