Statalist


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

Re: st: How to calculate 75 percentile of other individuals on thesame group


From   Joseph Coveney <jcoveney@bigplanet.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: How to calculate 75 percentile of other individuals on thesame group
Date   Sat, 29 Sep 2007 15:31:02 -0700

To finish:  an observation is going to lie beneath, above or on a given
percentile for it's group, so there's a smarter (more efficient) algorithm,
but a brute-force approach is shown below.

Joseph Coveney


clear *
set more off
set seed `=date("2007-09-29", "YMD")'
set obs 100
generate byte pid = _n
generate byte group = mod(_n, 10)
generate double response = uniform()
*
* Begin here
*
tempvar tmpvar0 tmpvar1
sort group
generate double p75 = .
generate double `tmpvar0' = .
quietly forvalues i = 1/`=_N' {
   replace `tmpvar0' = response if _n != `i'
   by group: egen double `tmpvar1' = pctile(`tmpvar0'), p(75)
   replace p75 = `tmpvar1' in `i'
   drop `tmpvar1'
   replace `tmpvar0' = .
}
drop `tmpvar0'
list in 1/20, noobs sepby(group)
exit


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index