Announcement

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

  • Question about Rank Across

    Good morning,

    I have 3 variables that I need to rank.
    There are some cells in those variables that contain no data.
    These I would like to have ranked as -1.
    Could anybody help me out please?


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(raceid prcaverage prclastrun prc2ndlastrun) float(rank_prcaverage rank_prclastrun rank_prc2ndlastrun)
    1 96 93 98  1  7  1
    1 91 90 89  9 10  6
    1 95 97 95  4  3  3
    1 93 94 94  6  5  4
    1 94 94 91  5  5  5
    1 96 96  .  1  4  .
    1 96  .  0  1  . 10
    1  . 93 96  .  7  2
    1 92 91 88  7  9  7
    1 92 99 86  7  1  9
    1 90 98 87 10  2  8
    end
    Here is the code that I am using at the moment...

    sort raceid
    foreach v in prcaverage prclastrun prc2ndlastrun {
    by raceid: egen rank_`v' = rank(-`v'),track
    }


  • #2
    egen's rank() function has wired in that it maps missings to missings. If I understand you correctly you need to replace such by -1 afterwards.

    Comment


    • #3
      Thanks Nick, I came up with a working solution of....

      foreach x of varlist rank_prcaverage rank_prclastrun rank_prc2ndlastrun rank{
      replace `x' = -1 if(`x' == .)
      }

      Comment


      • #4
        See also

        Code:
        help mvencode

        Comment


        • #5
          Thank you. Noted.

          Comment

          Working...
          X