One generalisation of such stuff is the -egen-
function -rndsub- in -egenmore- on SSC.
Nick
[email protected]
> Check out -by:- (various sections in the manual, plus
> a tutorial in Stata Journal 2(1):86-102 (2002)).
>
> set seed 31103
> set obs 100
> gen id = _n
> egen group = seq(), block(10)
> gen random = uniform()
> bysort group (random) : gen treatment = cond(_n <= 5, "A", "B")
> sort id
> l id group treatment
*
* 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/