Announcement

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

  • Help with percentile rank

    Dear Statalists,

    I am running into a problem when generating percentile rank for each individual. Suppose I have sorted by group_id and income, my data set goes like:

    group_id inidividual_id income nb

    1 11 1000 0
    1 12 1100 1
    1 13 1100 1
    2 21 1350 3
    2 22 1400 4
    3 31 1450 5
    3 32 1500 6
    3 33 1600 7
    4 41 1620 8
    4 42 1700 9

    The definition of percentile rank is rank_i=n_b/N
    n_b, number of individuals with income lower than income_i
    N, total number of individuals in the group.

    I have tried count, but it can only return one value and could not get nb correctly. Any suggestions will be welcomed. Thank you!


    Ruth

  • #2
    what you write is not entirely clear to me; however, assuming no ties, I think the following will give you what you want:
    Code:
    sort income
    egen rank=rank(income), track
    replace rank=rank-1
    gen pctrank=rank/N
    I also assume you know what N is

    Comment


    • #3
      See also http://www.stata.com/support/faqs/st...ing-positions/ for a detailed discussion taking Rich's approach further.

      Comment


      • #4
        See also Philippe Van Kerm's fracrank module:
        Code:
        net describe sgini , from(http://medim.ceps.lu/stata)
        and look also at the (linked) online help

        Comment


        • #5
          I will add only that there is more than one "official" method for calculating percentiles: http://www.itl.nist.gov/div898/handb...on2/prc262.htm .
          David Radwin
          Senior Researcher, California Competes
          californiacompetes.org
          Pronouns: He/Him

          Comment


          • #6
            Originally posted by Stephen Jenkins View Post
            See also Philippe Van Kerm's fracrank module:
            Code:
            net describe sgini , from(http://medim.ceps.lu/stata)
            and look also at the (linked) online help
            This fractional rank command is fantastic. Thanks!

            Comment

            Working...
            X