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

st: row-level counting command?

From   David K Evans <[email protected]>
To   [email protected]
Subject   st: row-level counting command?
Date   Fri, 28 Jan 2005 15:21:33 -0500 (EST)

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

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!


PhD student, Harvard Economics Department
Phone: (O) 617-495-5634, (H) 617 - 493 - 1536
Address: Currier Mail Center #554, Cambridge, MA 02138

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index