Statalist The Stata Listserver


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

Re: st: Creating quintiles with "xtile"


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Creating quintiles with "xtile"
Date   Mon, 26 Mar 2007 13:18:55 -0400

If there are no missings to account for, you can get there
like this:

 bys date (ret): gen newvar=ceil(_n*5/_N)

will do it.

hth,
Jeph


Yvonne Capstick wrote:
Hi,
I have a dataset of stock returns each month. For each month, I'd like to sort the stocks into quintiles. What I'd really like to do is something like:

sort date
by date: xtile newvar = ret, nq(5)

However, Stata doesn't let me combine "xtile" with "by". I can obviously get around this by looping through the dates, but this is time-consuming. In many other applications, I can use "by" to save on a loop (e.g. sort date, by date: egen newvar = mean(ret)) but I can't seem to use it here. Does anyone know of a more efficient way to generate my quintiles per month?

Thanks, Yvonne

_________________________________________________________________
Live Search Maps – find all the local information you need, right when you need it. http://maps.live.com/?icid=hmtag2&FORM=MGAC01

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


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