Announcement

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

  • Stata Percentiles

    Code:
    set obs 1000
    set seed 1
    generate x = runiform()

    Say I have variable 'x' which is uniform distribution variable and I wish to create Variable X where the values of 'x' are converted into a categorical variable and I specify the percentiles and theyre values where

    Code:
    'X' value in the percentile 0--28.9999 -> 'x' value of 1
    'X' value in the percentile 29--31.9999 -> 'x' value of 2
    'X' value in the percentile 32--97.999 -> 'x' value of 3
    'X' value in the percentile 98--100 -> 'x' value of 4

  • #2
    Code:
    _pctile x, percentiles(29 32 98)
    return list
    
    gen wanted = 1 if x < r(r1)
    replace wanted = 2 if x >= r(r1) & x < r(r2)
    replace wanted = 3 if x >= r(r2) & x < r(r3)
    replace wanted = 4 if x > r(r3)

    Comment

    Working...
    X