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

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

From   "Martin Weiss" <>
To   <>
Subject   st: AW: Splitting panel in 3 groups: gen byte
Date   Wed, 17 Jun 2009 10:25:56 +0200


So John, just to be sure: The random numbers from the uniform distribution
are -generate-d to determine a random sort order, and the -gen byte-
statement uses the fact that the in-built _n and _N are calculated within
groups determined by the by groups. The condition passed to the -cond()-
function says that the data which has been sorted randomly should now be
assigned values for the group identifier "group", "1" for the first half (
where the running number _n is smaller/equal to half the number of
observations in a by group), and 2 for the remainder...


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


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,


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

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

Faculty page:

Personal page:

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index