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

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

From |
Sarah Elizabeth Edgington <sedging@ucla.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: counting variables within a row |

Date |
Tue, 08 Jun 2010 17:20:31 -0700 |

Casey,

To get your first count it might look something like this: gen lightcount_d1=0 foreach num in one two three four five { replace lightcount_d1=lightcount_d1+1 if met_a`num'>0 & met_a`num'<3 } There may be other ways to do this but this is the first that occurs to me. -Sarah At 04:15 PM 6/8/2010, you wrote:

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 criteria. Any thoughts on how to handle this? Thanks in advance. * * 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/

* * 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**:**RE: st: counting variables within a row***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: counting variables within a row***From:*Steve Samuels <sjsamuels@gmail.com>

**References**:**st: counting variables within a row***From:*"Casey P. Durand" <durandca@usc.edu>

- Prev by Date:
**Re: st: counting variables within a row** - Next by Date:
**Re: st: Re: QUestion using -fs- package** - Previous by thread:
**Re: st: counting variables within a row** - Next by thread:
**Re: st: counting variables within a row** - Index(es):