Announcement

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

  • Categorize income variable due to quartiles

    Hello,

    I assume the solution is very simple, but I'm just standing at a loss....

    I have to categroize the income variable due to the quartils-distance. So the first category should include all people whose income is lessequal to p25. Category 2 should include all between p25-p75 and category 3 all n whose income is higher than p75.

    I suppose there is a stata command which I just don't find / get.

    Thank you so much in advance!

    Best regards,
    Larissa

  • #2


    Use xtile to throw away information as desired and then recode to throw away yet more.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . xtile binned=mpg, nq(4)
    
    . tabstat mpg, by(binned) s(n min max)
    
    Summary for variables: mpg
         by categories of: binned (4 quantiles of mpg)
    
      binned |         N       min       max
    ---------+------------------------------
           1 |        27        12        18
           2 |        11        19        20
           3 |        22        21        25
           4 |        14        26        41
    ---------+------------------------------
       Total |        74        12        41
    ----------------------------------------
    
    . recode binned 2/3 = 2 4 = 3, gen(binned2)
    (36 differences between binned and binned2)
    
    . tab binned*
    
             4 | RECODE of binned (4 quantiles of
     quantiles |               mpg)
        of mpg |         1          2          3 |     Total
    -----------+---------------------------------+----------
             1 |        27          0          0 |        27
             2 |         0         11          0 |        11
             3 |         0         22          0 |        22
             4 |         0          0         14 |        14
    -----------+---------------------------------+----------
         Total |        27         33         14 |        74
    This example is typical: ties can result in bins with unequal frequencies in practice.
    Last edited by Nick Cox; 20 May 2019, 07:53.

    Comment

    Working...
    X