Statalist


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

st: RE: groups by two or more variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: groups by two or more variables
Date   Thu, 28 Jun 2007 20:56:01 +0100

No one has yet replied to this, perhaps for
the same reason that I nearly didn't. 

I see here 

(a) some data 

(b) some code

(c) a question: "Is this the best approach?" 

I can't answer (c) on the basis of (a) and
(b) without knowing what you are trying 
to do. Perhaps that should be clear to me, 
but it isn't. 

Nick 
[email protected] 

Rajesh Tharyan
> 
> Is there a way to create groups (say 25 groups) by two 
> variables? Here X and
> Y,
> 
> Year	id	X	 Y
> 986	6215	1	.645
> 1986	1781	1	.778
> 1986	2774	1	.819
> 1986	6354	1	.921

< snip> 

> 1986	433	3271	.9935799
> 1986	753	4617	.7927225
> 1986	2675	4930	.7089249
> 1986	817	10212	.962593
> 
> I can create, quintiles of X and then for each of those 
> create quintiles of
> Y giving me 25 groups.
> 
> Using the following code
> 
> sort  X
> xtile mc=X,nq(5)
> 
> gen bm=.
> levels mc, local(levels)
> foreach i of local levels {
> xtile bm_`i'=Y if mc==`i',nq(5)
> replace bm=bm_`i' if mc==`i'
> drop bm_`i'
> }
> tostring bm mc,replace
> gen a=mc+bm
> 
> I want to see how this differs from a grouping based on a 
> double sort of X
> and Y. 
> 
> So I need to do
> 
> sort x y
> gen b=_n
> gen group=floor(_n/10) * as in this case I have 264 observations)
> 
> is this the best approach?

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