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

 From "Nick Cox" <[email protected]> To <[email protected]> Subject st: RE: Random numbers and egen cut() Date Thu, 6 Jan 2005 01:05:03 -0000

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