# RE: st: RE: Percentiles: Identify of smallest observation closet to percentile value

 From "Nick Cox" To Subject RE: st: RE: Percentiles: Identify of smallest observation closet to percentile value Date Tue, 4 Feb 2003 10:08:13 -0000

```Ronnie Babigumira
>
> Rod, this works for me
> . sum p, d
>
>                             Price
> -------------------------------------------------------------
>       Percentiles      Smallest
>  1%         3291           3291
>  5%         3748           3299
> 10%         3895           3667       Obs                  74
> 25%         4195           3748       Sum of Wgt.          74
>
> 50%       5006.5                      Mean           6165.257
>                         Largest       Std. Dev.      2949.496
> 75%         6342          13466
> 90%        11385          13594       Variance        8699526
> 95%        13466          14500       Skewness       1.653434
> 99%        15906          15906       Kurtosis       4.819188
>
> . list make price if price == `r(p75)'
>
>      make                   price
>  23. Dodge St. Regis        6,342
>
> **
> You may or may not use ur own macro. If u use ur own macro, the
> after sum p, d, you could
>
> local p75 = r(p75) (I notice u missed this step)
> and then list
>
> list make price if price == `p75'
>

As noted previously, this works because, for this sample
size, the quantile in question is a particular value
and thus at least one value is equal to it. But
as the documentation for -summarize- explains, some
quantiles are computed by splitting the difference

Try

. sysuse auto
. drop in 1/2
. su displ, d

The upper quartile is calculated as (231 + 250) / 2
and is not equal to any observed value. This
necessitates an approach based on finding whatever
minimises |value - quantile| = abs(value - quantile)
and several observations may tie on this criterion
(even if there are no ties in the data).

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```