Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Unique Randomization within groups

From   Jonah Rexer <>
Subject   st: Unique Randomization within groups
Date   Thu, 31 Jan 2013 15:14:44 +0300


I am doing a randomization among 3 groups (2 treatment and 1 control) for a
micro experiment.
Our sample is small, N=99 with the unit being a cluster (a group of 2-3
I have merged clusters to assign each a random number. But instead of
stratifying, since our sample is so small, I have organized each cluster
into a group of 3 clusters (so 33 groups, each with 3 clusters) based on
our stratification variables.

What I want to do is assign a random integer, 1-3, within each group. I've
used the command:

set seed 4109

bysort cluster_group : gen random1=floor((3-1+1)*runiform()+1)

The problem is that this doesn't give me a unique number. Within each
group, i need one observation (cluster) to be 1, one to be 2, and one to be
3. This is why I used bysort, but it doesn't seem to be making any
difference. Is there any way to ensure that the number assigned is unique
within the group?

Jonah Rexer
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index