, ,

Returning percentiles as scalars

When I wanted to store percentiles in a local, e.g. to indicate the median in a figure, I used to first sum var, detail local var_p50=`r(p50)’ The disadvantage of this approach is that you can only store pre-specified percentiles (i.e., 1, 5, 10, 25, 50, 75, 90, 95, 99), and it can be lengthy if…

When I wanted to store percentiles in a local, e.g. to indicate the median in a figure, I used to first

sum var, detail
local var_p50=`r(p50)'

The disadvantage of this approach is that you can only store pre-specified percentiles (i.e., 1, 5, 10, 25, 50, 75, 90, 95, 99), and it can be lengthy if you need to store several percentiles.

A bit of a shorter and nicer way is to use _pcentile. If you want to, for example, store the percentiles 5, 20, 80 and 95, you can write

_pctile ps1_pre, p(5 20 80 95)
which store the corresponding percentiles as locals r(r1)' to `(r4)' 

Tags:

Leave a Reply