Announcement

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

  • Grouping of a variable based on the percentile

    Hello everyone,

    I have a problem here and I don't understand why it doesn't work.
    I would like to create income groups that are divided according to the percentile, but I can't get the result I want.



    . sum Jahreseinkommen, detail

    Yearly total personal income, net
    -------------------------------------------------------------
    Percentiles Smallest
    1% 1800 100
    5% 7000 100
    10% 13200 100 Obs 16,542
    25% 27400 100 Sum of wgt. 16,542

    50% 54100 Mean 57633.57
    Largest Std. dev. 36314.36
    75% 80600 162500
    90% 109000 162600 Variance 1.32e+09
    95% 126700 163000 Skewness .5556764
    99% 151100 163200 Kurtosis 2.685073


    . gen Einkommensgruppe = .
    (16,542 missing values generated)

    . replace Einkommensgruppe = 1 if Jahreseinkommen < r(p25)
    (4,121 real changes made)

    . replace Einkommensgruppe = 2 if Jahreseinkommen >= r(q25) & Jahreseinkommen < r(q50)
    (0 real changes made)

    . replace Einkommensgruppe = 3 if Jahreseinkommen >= r(q50) & Jahreseinkommen < r(q75)
    (0 real changes made)

    . replace Einkommensgruppe = 4 if Jahreseinkommen >= r(q75)
    (0 real changes made)

    . label variable Einkommensgruppe "Einkommengruppen nach Perzentilen"

    . label define Einkommensgruppe_l 1 "1. Einkommensgruppe" 2 "2. Einkommensgruppe" 3 "3. Einkommensgruppe" 4 "4. Einkommensgruppe"

    . label values Einkommensgruppe Einkommensgruppe_l

    . tab Einkommensgruppe

    Einkommengruppen |
    nach Perzentilen | Freq. Percent Cum.
    ---------------------+-----------------------------------
    1. Einkommensgruppe | 4,121 100.00 100.00
    ---------------------+-----------------------------------
    Total | 4,121 100.00



    if anyone knows what the problem is or can help me, I would be delighted.








  • #2
    r(q25) is a typo for r(p25) and so forth.

    That said, xtile does what you want to do directly.

    Comment

    Working...
    X