Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to rank from highest to lowest


    I'm trying to rank observations, but would like to give no 1 to the highest number. I have tried ranking by using the command below, but i couldn't seem to reverse the ranking in the way I want. bysort group_id (var_to_rank): gen desired_rank = sum(var_to_rank != var_to_rank[_n-1])

  • #2
    look at the help for -egen- and, in particular, look at the "rank" function within egen

    Comment


    • #3
      The manual entry for egen spells out what is a most useful trick here (and a very obvious one once you see the point):

      Most applications of rank() will be to one variable, but the argument exp can be more general,
      namely, an expression. In particular, rank(-varname) reverses ranks from those obtained by rank(varname).

      Last edited by Nick Cox; 28 Jan 2015, 10:02.

      Comment


      • #4
        Thank you very much!!

        Comment

        Working...
        X