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.
//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.
Comment