[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

# Re: st: is there a syntax that inverts what -centile- does?

 From "Austin Nichols" <[email protected]> To [email protected] Subject Re: st: is there a syntax that inverts what -centile- does? Date Thu, 10 Jan 2008 21:57:08 -0500

```Yang--
If you have an arbitrary value, say x=30, and want to calculate what
quantile (rank or percentile) it would occupy in your data X, one easy
way is to calculate rank for X, create an extra fake obs with the
value 30, and interpolate rank with respect to X.  Here is a worked
example:

* set up example:
webuse nhanes2, clear
g bmi=wei/hei^2*10^4
svyset
g mi=mi(bmi,finalw)
bys mi (bmi): g srank=sum(finalwgt) if mi==0
by mi: g r=(srank-srank[1]/2)/srank[_N] if mi==0

* now see what quantile 30 corresponds to:
set obs `=_N+1'
replace bmi=30 in l
ipolate r bmi, gen(est)
li est r bmi in l
drop est
drop in l

* check answer:
_pctile bmi [pw=fin], nq(100)
di r(r85)
di r(r86)

Note that I calculate r (quantile rank) as a proportion between 0 and
1 using weights; if you have unweighted data, you can generate a
weight variable=1 everywhere or equivalently use

bys mi other (bmi): g r=(_n-1/2)/_N if mi==0

in place of

bys mi other (bmi): g srank=sum(finalwgt) if mi==0
by mi other: g r=(srank-srank[1]/2)/srank[_N] if mi==0

On Jan 10, 2008 5:23 AM, Ben Jann <[email protected]> wrote:
> Maybe also the -relrank- command is of help (or the -mm_relrank()-
> Mata function from the -moremata- package). See

> On Jan 10, 2008 5:03 AM, Alan Neustadtl <[email protected]> wrote:
> > help pctile might be useful as well as reading the FAQ title "How can
> > I calculate percentile ranks?
> > How can I calculate plotting positions?"  written by Nick Cox.  The
> > URL is http://www.stata.com/support/faqs/stat/pcrank.html

> > On Jan 9, 2008 9:09 PM, Yang Lu <[email protected]> wrote:
> > > But what if I have some arbituary values and want STATA to return
> > > their percentile? I know I can write a do file to make it automatic
> > > but would be surprised if such a syntax did not already exist (though
> > > I didn't find it. I use stata 9.) I'm sorry if someone asked this
> > > before; I'm new to the list but I did check before I wrote this email.
> > > Thanks a lot!
*
*   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/
```

 © Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index