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   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: display identifiers accounting for duplicate obs
Date   Fri, 4 May 2012 15:34:08 -0500

bysort hits : generate byte _first = (_n=1)
generate long rank = sum( _first )

On Fri, May 4, 2012 at 3:27 PM, tashi lama <[email protected]> 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/



-- 
---- Stas Kolenikov
-- http://stas.kolenikov.name
---- Senior Survey Statistician, Abt SRBI
-- Opinions stated in this email are mine only, and do not reflect the
position of my employer

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