Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Random numbers and egen cut()


From   "Wallace, John" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Random numbers and egen cut()
Date   Thu, 6 Jan 2005 09:03:43 -0800

Thanks Nick, that worked nicely.  Do you know why didn't -egen
cut(),group()- produce similar results?  I thought when you specifed
group it would bin the -cut()- values into -group()- sets of equal size.
I thought perhaps there might be a problem with ties, but it seems
unlikely since the random values are floats.

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Wednesday, January 05, 2005 5:05 PM
To: [email protected]
Subject: st: RE: Random numbers and egen cut()

Well, random numbers are expected to 
display a certain amount of randomness... 

I'd 

. set obs 2400

and use -egen, seq()- before
and after 

. gen r = uniform()
. sort block r 

Nick 
[email protected] 

Wallace, John
 
> Happy New Year Statalist!
> 
> I have 6 blocks of 400 samples that I'd like to randomly 
> assign to groups of 50.  I thought I could do this with egen 
> cut, but I got unanticipated results
> 
> .set obs 6
> .gen block = _n
> .expand(400)
> .sort v1
> .egen id = fill(1/400 1/400)
> .gen random = uniform()
> .sort block random
> .egen group = cut(random), group(8)
> 
> .tab group block
> 
>       |                       block
> group |    1         2         3         4         5         
> 6 |  Total
> ------+-------------------------------------------------------
> -+-------
>     0 |   47        51        54        46        48        
> 54 |    300 
>     1 |   51        61        49        46        46        
> 47 |    300 
>     2 |   61        41        42        48        56        
> 52 |    300 
>     3 |   53        33        46        60        54        
> 54 |    300 
>     4 |   48        57        52        52        37        
> 54 |    300 
>     5 |   46        57        53        52        51        
> 41 |    300 
>     6 |   43        52        51        49        55        
> 50 |    300 
>     7 |   51        48        53        47        53        
> 48 |    300 
> ------+-------------------------------------------------------
> -+-------
> Total |  400       400       400       400       400       
> 400 |  2,400
> 
> What would have been a better way to do this?  

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

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