Announcement

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

  • xtile function

    Hello,

    how can I write this command but in the invers order, like to assign 5 to highest pay and 1 to lowest pay??


    egen quantileD = xtile(pay), by(year) nq(5)

    replace quantileD = 6 - quantileD

    Thks.




  • #2
    Please use a full real name on the forum: that means given name and family name.


    The function xtile() is from egenmore (SSC) : as with our policy on names please see the FAQ Advice to see that you are asked to explain this about user-written software you cite.

    All that said, I don't understand your question. The behaviour of xtile() is to assign highest quantile label to highest values. If you want to flip it round, you have one good technique, so what is the question please?

    Comment


    • #3
      I'll try to change my name now.

      Nick, this commando assign quintile 1 to highest values of pay and 5 to lowest values of pay and I'd like to rank in the opossite direction, where 5 quantile is the highest value and 1 is the lowest value.

      egen quantileD = xtile(pay), by(year) nq(5)

      replace quantileD = 6 - quantileD




      Comment


      • #4
        I don't understand this claim. Here is a demonstration that xtile() maps low to low and high to high. Here groups is from SSC.

        If you (think you) have some different behaviour, please show us a reproducible example.

        Code:
         
        . sysuse auto
        (1978 Automobile Data)
        
        . egen mpg5 = xtile(mpg), nq(5)
        
        . groups mpg*
        
          +------------------------------+
          | mpg   mpg5   Freq.   Percent |
          |------------------------------|
          |  12      1       2      2.70 |
          |  14      1       6      8.11 |
          |  15      1       2      2.70 |
          |  16      1       4      5.41 |
          |  17      1       4      5.41 |
          |------------------------------|
          |  18      2       9     12.16 |
          |  19      2       8     10.81 |
          |  20      3       3      4.05 |
          |  21      3       5      6.76 |
          |  22      3       5      6.76 |
          |------------------------------|
          |  23      4       3      4.05 |
          |  24      4       4      5.41 |
          |  25      4       5      6.76 |
          |  26      5       3      4.05 |
          |  28      5       3      4.05 |
          |------------------------------|
          |  29      5       1      1.35 |
          |  30      5       2      2.70 |
          |  31      5       1      1.35 |
          |  34      5       1      1.35 |
          |  35      5       2      2.70 |
          |------------------------------|
          |  41      5       1      1.35 |
          +------------------------------+

        Comment


        • #5
          Quim -

          If you reread the discussion in your initial post from January 28, you will see that after using the egen xtile function, you told us that the results were in the reverse order of what you needed: egen xtile put the highest numbers in quantile 5 and you needed the highest numbers to be the quantile 1, and so forth. In response to that, Clyde Schechter advised you to include a replace command like the one you included above, which changes 5 to 6-5=1, 4 to 6-4=2, and so forth.

          So in your current post you tell us you need the highest numbers to be in quantile 5. The answer is simple: do not include the replace command that you were given to make them quantile 1.

          As a piece of general advice, it appears that you have no idea what the replace command is doing, which suggests that you have not attempted to understand the solution you were given to your January problem, but have been copying it from program to program. To become a proficient independent user of Stata, along with reading documentation you should take the time to understand how answers you receive on Statalist function to address your problem.

          Comment

          Working...
          X