Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: counting variables within a row

From   "Martin Weiss" <>
To   <>
Subject   st: AW: counting variables within a row
Date   Wed, 9 Jun 2010 09:27:28 +0200


BTW, Casey, the -if- qualifier does not take -varlist-s, so that your first
qualifier does not, as you probably thought, condition on every one of those
eighteen vars being bigger than 0 and less than 3. It conditions on the
difference between the first and eighteenth being in that range. -egen,
rownonmiss()- does indeed expect a -varlist-, but not the qualifier...


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Casey P. Durand
Gesendet: Mittwoch, 9. Juni 2010 01:16
Betreff: st: counting variables within a row

Hi folks,

I have a dataset with 18 variables called met_aone-met_aeighteen.
Within each observation, I'm trying to count the number of these
variables with values which satisfy three criteria.  I thought I could
handle this with -egen- and the lines of code I originally wrote are:

egen lightcount_d1= rownonmiss ( met_aone-met_aeighteen) if (
met_aone-met_aeighteen)> 0 & ( met_aone-met_aeighteen)< 3
egen modcount_d1= rownonmiss (met_aone-met_aeighteen) if
(met_aone-met_aeighteen)>= 3.0000 & (met_aone-met_aeighteen)< 6
egen hardcount_d1= rownonmiss (met_aone-met_aeighteen) if
(met_aone-met_aeighteen)>= 6.0000 & (met_aone-met_aeighteen)< .

The problem as I quickly realized is that it is only counting
variables when every single value in the row satisfies the if
requirement.  What I can't figure out is how to assess each variable
individually for meeting the criteria, but ultimately producing a new
variable with the total within the observation which meets my

Any thoughts on how to handle this?

Thanks in advance.

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index