Hi, I am using the following loop to get the 0.5%, 1%, 2%, 5%, 95%, 98%, 99% and 99.5% percentiles for the variable "Return". However, STATA does not recognise the 0.5 and also the 99.5, I believe this is because these are not integers. Could anyone please help me, I would much appreciate this since I have been struggling for a while to get around this problem. I know I could get the 0.5 percentile and then use gen command to create my dummy variables, however I am required to use a more efficient way.
_pctile Return, percentiles( 0.5 1 2 5 95 98 99 99.5)
return list
local i = 1
foreach n of numlist 0.5 1 2 5 95 98 99 99.5 {
gen byte above`n' = Return >= `r(r`i')'
local ++i
}
Kind Regards,
Adrian
0 Response to Calculating percentiles in STATA
Post a Comment