Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Is there a "running count" command in Stata?


From   "Mingfeng Lin" <[email protected]>
To   <[email protected]>
Subject   st: Is there a "running count" command in Stata?
Date   Thu, 31 Aug 2006 11:03:44 -0400

Greetings!
 
I have checked the references as well as the Statalist archive, but couldn't
seem to find a solution to this.  I was trying to find some command that
works like a "running" count function; that is, it will give the number of
unique occurences from 1 to _n.  For example: variable x is as follows: 
 
x 
cd1
cd2
cd2
cd2
cd1
cd3
cd4
cd1
cd5
cd3
 
And I was trying to generate a variable -y- such that 

x              y
cd1          1
cd2          2
cd2          2
cd3          3
cd1          3 //there are cd1, cd2 and cd3 before this
cd3          3
cd4          4
cd1          4
cd5          5 
cd3          5
 
I am still learning Stata and was hoping that this does not have to be
solved by programming... Is there a command or package that works like this?

 
Many thanks!

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