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

RE: st: percentiles and locating a scalar in there.


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: percentiles and locating a scalar in there.
Date   Tue, 26 Jul 2005 00:38:38 +0100

This solution of directly counting below, at and 
above is exactly what sprang to my mind too. 

As Nick would acknowledge, his code 
is not industrial strength, one reason being 
the need to count missings too. 

Nick 
[email protected] 

Nick Winter
 
> Assuming your variable is mpg, and your scalar is 20.  Then how about 
> something like:
> 
> count if mpg>20
> local a = r(N)
> count if mpg<20
> local b = r(N)
> count if mpg==20
> local e = r(N)
> 
> di (`b'+`e'/2) / (`a'+`b'+`e')
> 
> That is, count how many observations are below s, how many 
> above, and how 
> many are equal.  Then the percentile is just the number 
> below, and half of 
> the ties, over the total N.

> >Hi, I have a question regarding percentiles that I've been 
> having some 
> >trouble with...suppose that you have a variable x, and you 
> have a scalar 
> >s, and you'd like to know at about what percentile of the x 
> variable the s 
> >scalar falls.  For instance, suppose x=1,2,3,...,1000.  Then 
> if you have 
> >s=20, it should be assigned the percentilie value of the 2nd 
> >percentile.  Is there a way to do this easily in stata? (I wanted to 
> >assign the scalar a n approximate percentile EVEN IF IT'S 
> NOT A VALUE in 
> >the variable itself so it can't be located in there)  
> Everything I could 
> >think of would take quite a while.

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