*! version 1.0.0 2April2015

Title

randtreatseq -- Random sequencing of treatments

Syntax

randtreatseq
,
sample(#)
[
{
treatments(#)
|
values(string)
}
seed(#)
replace
]

Required
sample(#) sample size

Optional
treatments(#) number of treatments that an individual
will be exposed to. Either treatments or values must be
provided, but not both

values(string) any set of values to represent the
treatments. Either treatments or values must be provided,
but not both

seed(#) set random-number seed to #

replace replaces data in memory

Description

randtreatseq generates treatments in a random sequence for each
individual in the sample, thereby reducing the potential for order
effects of multiple treatments.

As an example, let's assume that we want to conduct a study in which
each subject will be exposed to three treatments, sequentially. First,
we use power repeated to perform a sample size calculation for a
one-way repeated-measures model and determine that a sample size of 100
subjects is required. Next, we use randtreatseq to generate the
three treatments in random order for each of the 100 subjects.

Options

sample(#) sample size; required.

treatments(#) number of treatments that an
individual will be exposed to.

values(string) any set of values to represent the treatments.

Either treatments or values must be provided, but not both.

seed(#) set random-number seed to #.

replace replaces data in memory. An error message will be
generated if there is existing data in memory that has not been
saved and replace is not invoked.

Remarks

When a very large sample size has been specified, the user may encounter
an error message indicating that the maximum number of variables
allowed has been reached. In such instances, the user could reset the
maximum using set maxvar.

Examples

Generates 3 randomly sequenced treatments for a sample of 100
individuals, using a specified seed:

. randtreatseq, sample(100) treat(3) seed(12345678)

Same as above, but now specifying the desired values representing the 3
treatments, and replacing the data in memory:

. randtreatseq, sample(100) values(A B C) seed(12345678) replace

Run tabulate on the sequence variable to view the frequency and
type of treatment sequences generated:

. tab sequence

Output tables

randtreatseq produces several variables in a new dataset:

Variable Description

sequence a grouping of the treatment sequence

id an identifier for individuals in the sample

treat# the treatments

Stored results

randtreatseq stores the following in r():

Scalars

r(N) Sample size

r(Nseq) Number of unique sequences. In sufficiently large
samples, this value should equal the number of all possible permutations = [n! / (n-k)!]

References

Smeeton N, Cox NJ. Do-it-yourself shuffling and the number of runs under randomness. Stata Journal 2003;3(3):270-277.

Citation of randtreatseq

randtreatseq is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden, Ariel (2015). randtreatseq: Stata module for generating random sequencing of treatments

Author

Ariel Linden

President, Linden Consulting Group, LLC

Ann Arbor, MI, USA

alinden@lindenconsulting.org

http://www.lindenconsulting.org

Acknowledgments

I would like to thank Nicholas J. Cox for his support while developing randtreatseq

Also see

Online: pkshape, power repeated, ralloc (if installed), permin (if installed), nruns (if installed)