Bookmark and Share

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


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

Re: st: How to generate conditional random numbers?


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: How to generate conditional random numbers?
Date   Sun, 16 Jan 2011 16:07:23 +0000 (GMT)

--- On Sun, 16/1/11, Grace Jessie <[email protected]> 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: 
<http://econpapers.repec.org/paper/bocusug06/15.htm>
and:
<http://econpapers.repec.org/paper/bocdsug10/04.htm>

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index