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

Re: st: row-level counting command?


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: row-level counting command?
Date   Fri, 28 Jan 2005 15:36:40 -0500

Yes, there is an egen rcount command, in the egenmore package (available via ssc) that allows you to count using such a condition

Rich Goldstein

David K Evans wrote:


Dear Statalisters,

I have a household data set with the up-to 80 members of the household
listed horizontally, with each household being one observation. So, for
example, the ages of household members 1, 2, and 3 are in the following
variables:  age_1 age_2 age_3 ...

I want to create a variable that tells the number of people aged 15 in the
household.

One (very slow) way to do this is to create a loop and go through each of
the 80 people, then use robs:

for num 1/80: gen age15_X=1 if age_X==15
egen num_people_age15=robs(age15_*)

The problem with this is that it's so inefficient. Has anyone written a
command like "egen =robs" but that counts observations that satisfy a
certain condition rather than merely non-missing observations?

Thanks so much!
Dave


------------------------------------------------------------------------

PhD student, Harvard Economics Department
Phone: (O) 617-495-5634, (H) 617 - 493 - 1536
Address: Currier Mail Center #554, Cambridge, MA 02138
Website: www.people.fas.harvard.edu/~dkevans

------------------------------------------------------------------------
*
*   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