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]

From |
Maarten buis <maartenbuis@yahoo.co.uk> |

To |
statalist@hsphsun2.harvard.edu |

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 <gracejessie@hotmail.com> 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/

**Follow-Ups**:**RE: st: How to generate conditional random numbers?***From:*Grace Jessie <gracejessie@hotmail.com>

**References**:**st: How to generate conditional random numbers?***From:*Grace Jessie <gracejessie@hotmail.com>

- Prev by Date:
**RE: st: RE: RE: xtivreg2 -- Instruments dropped** - Next by Date:
**Re: st: Re: firthlogit** - Previous by thread:
**st: How to generate conditional random numbers?** - Next by thread:
**RE: st: How to generate conditional random numbers?** - Index(es):