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]

Re: st: display identifiers accounting for duplicate obs


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: display identifiers accounting for duplicate obs
Date   Fri, 4 May 2012 22:32:18 +0200

egen rhits = rank(hits)? 


-- 
010100100110111101101110011011100110100101100101




On Friday, May 4, 2012 at 10:27 PM, tashi lama wrote:

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



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