Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: display identifiers accounting for duplicate obs


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   st: display identifiers accounting for duplicate obs
Date   Fri, 4 May 2012 20:27:02 +0000

Hello all, 

       I can't come up with this solution despite spending quite some thought and time. The problem in hand sounds fairly straigh forward

 

I have a dataset like following 

 

hits

1

2

3

4

4

5

6

6

 

and I want to generate variable rank. Notice, if there were no duplicate obs, i would have said  

 

gsort -hits

gen rank=_n   and rank column would have given the ranks of the obs. That is what i want. 

 

However, there are some duplicate obs and i tried doing 

gsort -hits

gen rank=cond(hits[_n-1]==hits[_n], _n-1, _n) which would give me 

 

hits    rank

6        1

6        1

5        3

4        4

4        4 

3        6

2        7 

1        8    and that is not what I want. 

 

 

I looked at commands like generate, duplicates and I didn't see much relevant to my problem. 

 

 

Could someone give me a lead where to look at or which command should I dig in ? Thanks a lot.

 

Tashi 

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index