Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Re: count


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Re: count
Date   Wed, 11 Jan 2006 22:13:42 -0000

The syntax would need to be (e.g.) 

... c(@ == "A") 

-- or so I guess. 

-rcount()- just lurks in the SSC archive 
as one way to do this. Arguably, a better solution 
in general is to loop over variables 
using -foreach-, as earlier illustrated in this 
thread. That's more code, but it's 
exercising a general tool and saves learning 
about an extra function with idiosyncratic syntax. 

Nick 
[email protected] 

Steichen, Thomas J.
 
> victor michael zammit writes:
> > In version 8 ,how do you get to count the number of P's and 
> > A's for each Name
> > 
> > Hello Stata listers,
> > In version 8 ,how do you get to count the number of P's and 
> > A's for each Name
> > 
> > 
> >   Name D8  D9  D14  D15  D16  D19
> > 1.  Z      A    A    P      P       P     A
> > 2. G       P     A    P      P      A     P
> > 3. S       A      P    P      P      A    A
> > 4. An    A       P    P     A       P    P
> > 5. Ma    P       P    P      P     A     P
> 
> The egenmore function -rcount- would do this:
> 
>   . egen countA = rcount(D8 D9 D14 D15 D16 D19) , c(@ == A) 
>   . egen countP = rcount(D8 D9 D14 D15 D16 D19) , c(@ == P)
> 
> This generates variables whose values are the counts of A's 
> and P's in each observation.
> There may be an updated way to to this too...

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index