[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

# RE: st: from normal to bimodal distribution

 From Linn Renée Naper To Subject RE: st: from normal to bimodal distribution Date Mon, 17 Nov 2008 11:41:33 +0100

```Thanks a lot, I will try this and see how it works!

-----Opprinnelig melding-----
Fra: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] På vegne av Maarten buis
Sendt: 17. november 2008 11:45
Til: statalist@hsphsun2.harvard.edu
Emne: Re: st: from normal to bimodal distribution

--- Linn Renée Naper <linn.naper@ecgroup.no> wrote:
> How do I tell Stata to draw random variables or generate a stochastic
> variable with a bimodal distribution? Can the rnd-command by Hilde be
> used?

You can create a mixture of Gaussian (normal) distributions, like in
the example below: the local p represents the probability of belonging
to group 1, the locals mu1 and mu2 represents the means of group 1 and
2 respectively, and the locals sd1 and sd2 the standard deviations in
group 1 and group 2.

*--------------- begin example -----------------
drop _all
set obs 10000

local p = .5

local sd1 = .75
local sd2 = 1.5

local mu1 = -2
local mu2 = 2

gen u = uniform()
gen e = invnorm(uniform()) * ///
cond(u < `p', `sd1', `sd2') + ///
cond(u < `p', `mu1', `mu2')

hist e
*---------------- 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 N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

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