Statalist The Stata Listserver


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

st: generating random variable


From   "Mentzakis, Emmanouil" <[email protected]>
To   <[email protected]>
Subject   st: generating random variable
Date   Tue, 3 Apr 2007 17:26:52 +0100

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
1	1	3	1
2	2	1	1
2	2	1	0
2	2	2	1
2	2	2	0
2	2	3	0
2	2	3	1
3	1	1	0
3	1	1	1
3	1	2	1
3	1	2	0
3	1	3	0
3	1	3	1
4	2	1	1
4	2	1	0
4	2	2	0
4	2	2	1
4	2	3	1
4	2	3	0


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.

id	bl	set	choice
1	1	1	1
1	1	1	0
1	1	1	0
1	1	2	0
1	1	2	0
1	1	2	1
1	1	3	0
1	1	3	0
1	1	3	1
2	2	1	1
2	2	1	0
2	2	1	0
2	2	2	1
2	2	2	0
2	2	2	0
2	2	3	0
2	2	3	0
2	2	3	1
  .
  .
  .


Any help would be much appreciated.

Thank you
Manos


*
*   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