Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Re: RE: Re: generating random variable


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Re: RE: Re: generating random variable
Date   Tue, 03 Apr 2007 15:16:34 -0400

woops, please change :

gen choicenum=_n

into

bysort id bl set : gen choicenum=_n



----- Original Message ----- From: "Michael Blasnik" <[email protected]>
To: <[email protected]>
Sent: Tuesday, April 03, 2007 3:12 PM
Subject: st: Re: RE: Re: generating random variable



The choice is random as coded -- that's why the code generates a random number and uses that in the sort. I guess you need a way to actually track where it was in the sort order to begin with..

expand 2
gen random=uniform()
gen choicenum=_n
bysort id bl set (random): gen byte choice=_n==_N

Now you can see that the choice is set randomly to one of the two values of choicenum in each set.
*
*   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