Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: re: percentiles


From   "NEYMOTIN, FLORENCE" <[email protected]>
To   [email protected]
Subject   Re: st: re: percentiles
Date   Mon, 25 Jul 2005 17:03:29 -0700

On Mon, 25 Jul 2005 19:58:53 -0400
 Kit Baum <[email protected]> wrote:
Florence wants to invert the pctile function.

program invpctile, rclass
version 8.2
syntax varname [if] [in], value(real) [nq(integer 100)]
tempvar pcts
* local nq 100
marksample touse
pctile `pcts' = `varlist' if `touse', nq(`nq')
qui replace `pcts' in 1/`nq' = abs(`pcts' - `value')
su `pcts' in 1/`nq', meanonly
qui replace `pcts' in 1/`nq' = cond(`pcts' == r(min),_n,.)
su `pcts' in 1/`nq',meanonly
return scalar pctile = r(mean)
end


. webuse dow1, clear

. invpctile dowclose, value(700)

. return list

scalars:
r(pctile) = 28


If you pctile dowclose, nq(100) you will see that a Dow of 700 is closest to the 28th percentile.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

*
* 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/
*
*   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