Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Splitting panel in 3 groups: gen byte
Date   Wed, 17 Jun 2009 09:54:16 +0200

<> 


That was a little trick to get a random order into your panel. You want to
take a look at Nick`s 
http://www.stata-journal.com/sjpdf.html?articlenum=pr0016
and
http://www.stata-journal.com/sjpdf.html?articlenum=pr0004
to get a grip on this thing.

As the first article shows, you can extend the -cond()- to several nested
conditions. For three groups and w/o the "i", which complicates things at
first:

********
clear*
set obs 10000

gen random=runiform()
sort random
gen byte group=cond(_n<=_N/3,1, ///
				cond(_n>_N/3&_n<=_N*2/3,2, ///
					3))
ta group
********


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von John Antonakis
Gesendet: Mittwoch, 17. Juni 2009 09:47
An: [email protected]
Betreff: st: Splitting panel in 3 groups: gen byte

Hi:

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.

Thank you in advance,
John.

-- 
____________________________________________________

Prof. John Antonakis
Associate Dean Faculty of Business and Economics
University of Lausanne
Internef #618
CH-1015 Lausanne-Dorigny
Switzerland

Tel ++41 (0)21 692-3438
Fax ++41 (0)21 692-3305

Faculty page:
http://www.hec.unil.ch/people/jantonakis&cl=en

Personal page:
http://www.hec.unil.ch/jantonakis
____________________________________________________

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


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