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
Nick
[email protected]
Banya, Winston
> Thank you very much for this Nick. I however have an
> extension to the
> question. What if I want to do the same exercise for say
> 100 subjects but
> ensuring that for every 10 subjects then number of
> treatments are equal i.e
> A=5 B=5.
*
* 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/