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]

From |
tashi lama <ltashi32@hotmail.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: display identifiers accounting for duplicate obs |

Date |
Mon, 7 May 2012 19:19:06 +0000 |

This actually works if you want to rank lowest to highest. Meaning, lowest one will get rank 1, second lowest will get rank 2 and highest will be ranked last. If you are doing the opposite i.e. giving highest obs rank1, second highest rank 2, then looks like you run out of option. ---------------------------------------- > Date: Fri, 4 May 2012 15:34:08 -0500 > Subject: Re: st: display identifiers accounting for duplicate obs > From: skolenik@gmail.com > To: statalist@hsphsun2.harvard.edu > > bysort hits : generate byte _first = (_n=1) > generate long rank = sum( _first ) > > On Fri, May 4, 2012 at 3:27 PM, tashi lama <ltashi32@hotmail.com> 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/ * * 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/

**References**:**st: display identifiers accounting for duplicate obs***From:*tashi lama <ltashi32@hotmail.com>

**Re: st: display identifiers accounting for duplicate obs***From:*Stas Kolenikov <skolenik@gmail.com>

- Prev by Date:
**st: mi impute chained, interactions, and the force option** - Next by Date:
**RE: st: display identifiers accounting for duplicate obs** - Previous by thread:
**Re: st: display identifiers accounting for duplicate obs** - Next by thread:
**st: How to test for heteroskedasticity and residuals w.r.t. "treatreg" command?** - Index(es):