Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Computing percentiles for each date
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Computing percentiles for each date
Date
Mon, 8 Jul 2013 08:04:46 +0100
You should not be surprised. You are using
pctile(exp) [, p(#)]
when you need
rowpctile(varlist) [, p(#)]
The syntax of -pctile()- is that it takes an expression, which cannot
be a varlist with two or more variable names. As it has happens, and
as you report
r1-r1000
has an interpretation as an expression, but e.g.
r*
does not. This is all documented in the help for -egen-.
Nick
[email protected]
On 8 July 2013 05:52, George Murray <[email protected]> wrote:
> I am working with time series data, and my variables consist of
> monthly returns for 1000 stocks (so the variables are
> date,r1,r2,r3,...,r1000). For each date, I would like to find the 90th
> percentile-return. That is, the return of the stock with the 100th
> highest return, at each date.
>
> I have tried using -by date: egen p90 = pctile(r1-r1000)-, but Stata
> interprets the 'r1-r1000' as the variable defined by r1 minus r1000,
> rather than the 90th percentile of the returns at each date. This
> approach works if I want to find the mean return at each date, using
> -egen mean = rmean(r1-r1000)-, but I am not sure if there is an
> equivalent code to find percentiles. Does anyone have any ideas on how
> to do this?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/