# 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
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/
```