Announcement

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

  • Using forvalues to generate percentile values across distinct values of a given variable

    I am trying to compute 99th percentile value across distinct values of a given variable. Basically, i am trying to generate a variable "p99_depth" which shows the 99th percentile value for values of depth corresponding to each individual instrument. My knowledge of STATA is fairly limited and this is the code i came up with:

    //i generated a new variable 'group' to number each distinct value across my variable of interest (instrument):

    egen group = group(instrument)
    su group, meanonly
    forvalues i = 1/`r(max)' {
    gen p99_depth = pctile(depth), p(99) if group == i
    }

    This is giving me invalid syntax error. Any help fixing the code or an alternative approach to solving this problem would be appreciated. Thanks.
    Last edited by Leonie Schneider; 26 Jan 2017, 09:05.

  • #2
    http://www.statalist.org/forums/foru...rvalues-pctile

    Comment

    Working...
    X