Bookmark and Share

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]

st: RE: Dividing data into quintiles


From   "Radwin, David" <[email protected]>
To   <[email protected]>
Subject   st: RE: Dividing data into quintiles
Date   Mon, 28 Oct 2013 14:58:16 -0400

Clarice,

If I understand correctly, you merely need to loop through each value of yrmonth and calculate quintiles for observations with that value for yrmonth. But you can't generate a new variable 151 times. 

So you could do something this that creates quintiles for a temporary variable:

gen quintile = .
quietly levelsof yrmonth, local(levs)
foreach lev of local levs {
	tempvar quint
	xtile `quint' = return if rtype=="formation" & yrmonth == "`lev'", n(5)
	replace quintile = `quint' 
	}


David
--
David Radwin
Senior Research Associate
Education and Workforce Development Division
RTI International
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-665-8274

www.rti.org


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Clarice Martins
> Sent: Monday, October 28, 2013 11:39 AM
> To: [email protected]
> Subject: st: Dividing data into quintiles
> 
> Dear group,
> 
> I need to select a sub-group of my dataset and cut it into quintiles, in
> order to proceed with calculations with top and bottom quintile.
> 
> - I use Stata 12.1 (for Mac)
> 
> - my data looks like this (now, after considerations from the group, thank
> you!)
> 
> co_id ticker rtype	yrmonth return
> 1 ABCB formation jun2000 0.01
> 1 ABCB buysell jul2000 0.01
> 1 ABCB holding ago2000 0.01
> 2 AEDU formation jun2000 0.01
> 2 AEDU buysell jul2000 0.01
> 2 AEDU holding ago2000 0.01
> 3 AMBV formation jun2000 0.01
> 3 AMBV buysell jul2000 0.01
> 3 AMBV holding ago2000 0.01
> 
> - i tryed both -egen cut- and -xtile-
> 
> egen quintile = cut(return) if rtype=="formation", group(5)
> 
> xtile quintile=return if rtype=="formation", n(5)
> 
> - when I use -if rtype=="formation"- both commands work fine!
> 
> - But, I need to select all observations rtype=="formation"  AND
> yrmonth=="jun2000", then cut this subgroup into quintiles
> 
> - Then, I need to proceed with this filter/select and cut, for every
> yrmonth (151 periods) on my data set
> 
> Any suggestions?
> 
> Thank you very much!
> 
> Clarice


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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index