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

 From Nick Winter <[email protected]> To [email protected] Subject RE: st: percentiles and locating a scalar in there. Date Tue, 26 Jul 2005 11:21:43 -0400

```Indeed -- at the very least it should be

count if mpg>20 & !missing(mpg)

Even better would be to use summarize, which would then allow weights, etc etc.

--Nick

At 07:38 PM 7/25/2005, you wrote:
```
```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

> 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/
```
--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601
*
* 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/