--- Viktor Slavtchev <[email protected]> wrote:
> how can I create a random sample of size N of discrete (dichotomous)
> variable (0=no; 1=yes)?
You can use function uniform(), which will create a random draw from a
uniform distribution between zero and one, so all values between zero
and one are equally likely to be returned. So 50% of the cases in a
variable created with uniform() will contain a value less than .50, 60%
will contain a value less than .60, etc.
*----------- begin example ------------
local N = 500
set obs `N'
/*For a fixed probability, say 50%*/
gen yes = uniform() < .5
/*For a probability that depends on x
through a logistic regression equaiton */
gen x = invnorm(uniform())
gen y = uniform() < invlogit(-1 + x)
*--------------- end example --------------
(For more on how to use examples I sent to the Statalist, see:
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html
*
* 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/