Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: FW: RE: RE: AW: Splitting panel in 3 groups: gen byte


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: FW: RE: RE: AW: Splitting panel in 3 groups: gen byte
Date   Wed, 17 Jun 2009 15:09:43 +0100

<> 

Remember to set the seed for repeatability. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 17 June 2009 12:18
To: [email protected]
Subject: st: RE: RE: AW: Splitting panel in 3 groups: gen byte

Nick 
[email protected] 


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 17 June 2009 09:15
To: [email protected]
Subject: st: RE: AW: Splitting panel in 3 groups: gen byte

With three or more groups, it is perhaps easier to move to 

gen random=runiform()
sort i random
by i: gen byte group = ceil(3 * _n/_N) 

"for any value of 3" (hoary mathematical joke) 

Nick 
[email protected] 

Martin Weiss

Also note Nick`s http://www.stata.com/support/faqs/stat/sampling.html

John Antonakis

Martin recently helped with me with some code, to randomly split panel 
data equally into two groups (which I then collapsed afterwards).

I am trying to understand the code regarding the split. My panel 
identifier is "i".

I had:

gen random=runiform()
sort i random
by i: gen byte group=cond(_n<=_N/2,1,2)

So, how to I split into 3 groups or 4 groups?  I am not sure what the 
"gen byte" command does and how the numbers 2,1,2 relate to the command.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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