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
Related Posts with Calculating percentiles in STATA
2SLS for Poisson regressionHi, I have a question about my data analysis. I am using 2SLS and the dependent variable is count da…
Destring retuned to double instead of floatI have de-stringed some variables and were converted from string to double. I would like to convert …
Number of Days since 52 Weeks High PriceHello everyone, I have daily unbalanced panel data with ID = permno and Time = date. The variable p…
Web ScrapingI recently came across a web scraping tool nfl2stata developed by Chris Hassel {https://blog.stata.c…
Dialog programmingI want to write a dialog that has functionality similar to the dialog: Data > Data utilities >…
Subscribe to:
Post Comments (Atom)
0 Response to Calculating percentiles in STATA
Post a Comment