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

st: re: percentiles


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: percentiles
Date   Mon, 25 Jul 2005 19:58:53 -0400

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/




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