Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
daniel klein <klein.daniel.81@googlemail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Sun, 4 Dec 2011 14:30:09 +0100 |

Phillip, using Nick's code would in this case probably be best, as it creates both quantities in one run and I think it might be a bit faster than using -egen-. However in the special case you reported, .i.e. your 10 variables do only take values 0, 1 or 2, then you can easily get the desired sum multiplying -egen-'s -anycount- result by 2. egen byte count = anycount(var_101-var_110) ,v(2) g byte sum = 2 * count if count Best Daniel -- [...] I actually needed both, counting the number of variables with value "2": egen var1 = anycount(var_101-var_110), values(2) and computing the sum across these variables (sorry for the imprecise question). * * 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/

- Prev by Date:
**Re: st: How can I count the number of variables that meet a certain condition per observation?** - Next by Date:
**st: multinominal logit model with panel data** - Previous by thread:
**Re: st: How can I count the number of variables that meet a certain condition per observation?** - Next by thread:
**R: st: Re:** - Index(es):