Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: How to generate conditional random numbers?

 From Grace Jessie <[email protected]> To <[email protected]> Subject RE: st: How to generate conditional random numbers? Date Sun, 16 Jan 2011 18:13:15 +0000

```Maarten,
thank you a lot.
I will read the papers you recommended later.
Thank you for all the resources you provided.

Grace

----------------------------------------
> Date: Sun, 16 Jan 2011 16:07:23 +0000
> From: [email protected]
> Subject: Re: st: How to generate conditional random numbers?
> To: [email protected]
>
> --- On Sun, 16/1/11, Grace Jessie wrote:
> > I have a variable x generated randomly ranging from 85 to
> > 95. Now I want to generate three variables whose mean equals x
> > and they are all on the interval [80,95).
> > How to generate these conditional variables randomly?
>
> This all depends on the distribution you want to assume for your
> variables. Since you want a bounded variable, one possibility is
> the beta distribution. The -rbeta()- function uses the standard
> parameterization for this distribution, so it takes arguments
> a and b, neither of which is the mean. So you first need to
> translate the parameters from a parameterization that includes
> the mean to the standard parameterization. These 2
> parameterizations are discussed here:
>
> and:
>
>
> These two presentations give you all the elements you need to
> derive the required translation, which I leave as an excercise.
>
> Below is an example of how to draw such samples in Stata:
>
> *---------- begin example -----------
> drop _all
> set obs 100
>
> gen mu = runiform()
> gen x = 11*mu+ 84
>
> scalar phi = 10
> gen a = mu*phi
> gen b = (1-mu)*phi
>
> forvalues i = 1/3 {
> gen r`i' = 20*rbeta(a, b)+80
> }
> drop a b
> sum
> *---------- end example --------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
>
> Hope this helps,
> Maarten
>
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://www.maartenbuis.nl
> --------------------------
>
>
>
>
> *
> * 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/
```