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

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

From |
"Schreck, Philipp" <[email protected]> |

To |
"[email protected]" <[email protected]> |

Subject |
st: How can I count the number of variables that meet a certain condition per observation? |

Date |
Sat, 3 Dec 2011 12:49:18 +0100 |

Dear list members, Say my dataset includes 10 observations and 10 variables, var101-var110. Entries can take values 0, 1, or 2 (I use Stata/SE 11). I would like to count for each observation the number of variables that meet a certain condition, say var*==2. Although I searched the list, I cannot find the appropriate command and would be very grateful for any suggestions. I could loop over var101-var110 and (for each var) generate a new variable with value "1" if the respective variable is greater than 1 (and then use -rsum- with the new variables). But that seems overly complicated and I was wondering whether there's an easy command I've been missing. Maybe it could be something like: egen varcount = rowtotal (var101-var110) but then I get the sum of all values (across vars) per observation which is not what I want. Is there a simple way of computing the sum across variables (for each observation) ONLY for those variables with values greater than 1 (or, alternatively, the number of variables with values greater than 1 per observation)? Thank you very much for your consideration, I appreciate any suggestions. Philipp * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:

- Prev by Date:
**Re: st: mmregress question** - Next by Date:
**Re: st: How can I count the number of variables that meet a certain condition per observation?** - Previous by thread:
**Re:Re:st: MLE for Tobit I** - Next by thread:
**Re: st: How can I count the number of variables that meet a certain condition per observation?** - Index(es):