Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Maarten Buis <maartenlbuis@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Pseudorandom Number from Supplied Table of Probabilities (Equivalent of SAS Rand("Table") Function) |

Date |
Mon, 6 Aug 2012 15:34:58 +0200 |

On Mon, Aug 6, 2012 at 2:51 PM, Mustafa Hirji wrote: > I would like to select one number from a a pre-defined set, where the probability of selecting each number is known. *----------- begin example ----------- clear set obs 100 //P(x=1) = .5 //P(x=2) = .2 //P(x=3) = .3 gen u = runiform() gen x = cond(u < .5, 1, /// cond(u < .7, 2, 3)) //P(y=1) = P(y=2)=...=P(y=6) = 1/6 gen y = ceil(6*runiform()) *------------ end example ------------ (For more on examples I sent to the Statalist see: http://www.maartenbuis.nl/example_faq ) For more see: M.L. Buis (2007), "Stata tip 48: Discrete uses for uniform()", The Stata Journal, 7(3), pp. 434-435. <http://www.stata-journal.com/article.html?article=pr0032> and <http://blog.stata.com/2012/07/18/using-statas-random-number-generators-part-1/> Hope this helps, Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin 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/

**References**:**st: Pseudorandom Number from Supplied Table of Probabilities (Equivalent of SAS Rand("Table") Function)***From:*Mustafa Hirji <mustafa.hirji@mail.utoronto.ca>

- Prev by Date:
**Re: st: Stata extremely slow on bsqreg and sqreg command** - Next by Date:
**Re: st: Comparing Regression Coefficients Across Subsamples** - Previous by thread:
**Re: st: Pseudorandom Number from Supplied Table of Probabilities (Equivalent of SAS Rand("Table") Function)** - Index(es):