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

st: RE: RE: RE: Re: random allocation [was:RE: programming question]


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: Re: random allocation [was:RE: programming question]
Date   Mon, 3 Nov 2003 15:09:00 -0000

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index