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

st: RE: counting values across variables

From   "Nick Cox" <>
To   <>
Subject   st: RE: counting values across variables
Date   Thu, 14 Apr 2005 17:57:03 +0100

I am not familiar with SPSS, which 
I understand to be a statistical package, 
but this sounds like 

gen count = 0 
qui foreach v of var a1-a21 { 
	replace count = count + (`v' == 5) 

There is an -egen- function -rcount()- 
in -egenmore- on SSC, for which the syntax
would be 

egen count = rcount(a1-a21), cond(@ == 5) 

but the approach from first principles 
gets higher marks from -egen--haters. 


Jason Thompson
> Is there a Stata equivalent of the SPSS count function, which 
> counts the 
> number of occurrences of a particular value amongst a set of 
> variables? 
> Something like this:
> count (newvar)=a1 to a21 (5), which assigns newvar the number 
> of times 
> a1-a21 equals 5 for each case?
> Nothing in egen seems to be quite what I'm looking for.

*   For searches and help try:

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