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

Re: st: Generating block randomation schedule using Stata


From   Gary Longton <glongton@fhcrc.org>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Generating block randomation schedule using Stata
Date   Wed, 27 Aug 2003 11:54:29 -0700

Rolf Klemm wrote:

I want to generate a randomization schedule for a study with 2 arms
for a sample size of 800 with a block size of 8, or 100 blocks of 8.
Is there a way to do this in Stata?
and Nick Cox replied:

If I understand this correctly, you want to set up
a repeated list of identifiers and then shuffle it.
This illustrates some technique:

. set obs 800
. egen id = seq(), to(8)
. egen block = seq(), block(8)
. * or choose a different pie
. set seed 314159
. gen random = uniform()
. sort block random
. list block id

An alternative to -egen, seq()- is -egen, repeat()- on SSC.
That will repeat sequences other than contiguous integers.
I suspect that Rolf is looking for a permuted-block randomization scheme for his 2-arm trial; i.e. he wants balanced assignment to study arms within blocks (4 subjects to each arm in this case), but with random permutations of the arm assignment order.

Nick's solution gives random permutations of sequential id's within blocks, but doesn't provide the arm assignment order for a 2-arm study. However, a slight modification of Nick's code should achieve this:

.clear
.set obs 800
.egen arm = seq(), to(2)
.egen block = seq(), block(8)
.set seed 314159
.gen random = uniform()
.bysort block (random): gen byte seqn = _n
.bysort block (seqn): l seqn arm

where seqn is the assignment order within each block.

- Gary





*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index