Thank you Michael,
What you proposed creates what I want apart from the fact that it does
not have the random assignment.
However, I think that I kind of need that. What I am trying to do is to
create individuals' choices from a choice experiment. Each individual
faces 3 questions (sets), which themselves consist of two alternatives.
If I was to always assign the "one" of the "choice" variable in the
second alternative that would mean that the individuals always choose
that alternative, which sound strange.
I know that it does not really matter, how I assign it since this is
just an exercise with simulated data but I was wondering if you could
think of a way to make the choice random.
Thanks a lot
Manos
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael
Blasnik
Sent: 03 April 2007 18:29
To: [email protected]
Subject: st: Re: generating random variable
This seems fairly simple:
expand 2
gen random=uniform()
bysort id bl set (random): gen byte choice=_n==_N
To make it 3 alternatives, just change expand 2 to expand 3. There is
really no point in creating the random variable in this approach since
all observations within a set are identical, so you could just assign it
to the last observation without randomly sorting.
Michael Blasnik
----- Original Message -----
From: "Mentzakis, Emmanouil" <[email protected]>
To: <[email protected]>
Sent: Tuesday, April 03, 2007 12:26 PM
Subject: st: generating random variable
> Dear all,
>
> I need to create a variable "choice" that will take the value of 0 or
1
> randomly (but in each set there has to be one occurrence of "one" and
> one occurrence of "zero"). I need the various respondents (id) to have
> different "choice" for the same "bl and "set", but I assume this is
> taken care by the random nature of the creation of the "choice"
> variable.
>
> id bl set choice
> 1 1 1 1
> 1 1 1 0
> 1 1 2 0
> 1 1 2 1
> 1 1 3 0
<snip>
>
> I would also like to create the same kind of "choice" variable but
where
> each "set" has three alternatives (one occurrence of "one" and two
> occurrences of "zero"), i.e.
<snip>
> Any help would be much appreciated.
*
* 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/
*
* 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/