[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Joseph Coveney <[email protected]> |

To |
Statalist <[email protected]> |

Subject |
Re: st: simulating bernoulli random numbers |

Date |
Thu, 03 Jul 2003 10:48:12 +0900 |

Thomas Mählmann asked about generating random numbers of a Bernoulli distribution,
and Roger Newson described the standard procedure that utilizes the -uniform()-
pseudorandom number generating function. (Yesterday, Nix Cox responded similarly to
essentially the same question from Feiyean.)

There is also a versatile suite of pseudorandom number generators written by Joseph
Hilbe and Walter Linde-Zwirble, with later help from Thomas Steichen, for a variety of
distributions (-findit rnd-). I use the suite extensively in sample size/power estimations
and other simulations.

If you look at the code of the two functions for binomial random variates (-rndbin- and -
rndbinx-), it seems that the there are several variations on the -generate byte randu =
uniform() <= pi- approach mentioned by Roger and Nick. The variations handle
situations involving small denominators (series of Bernoulli trials) and small expected
numbers (small pi). I recommend considering using these commands in lieu of

-generate byte randu = uniform() <= pi-, especially if your problem might involve either
of these special circumstances.

Joseph Coveney

P.S. The suite was written for an early release of Stata, and so it uses Stata's old
pseudorandom number generating function (-set seed0-), and other superceded Stata
commands. In order to make it run more quickly and in order to have it use the modern
pseudorandom number generator, I modified the code for the two commands that I use
most often (for the binomial distribution, -rndbin- and -rndbinx-), placing the two
commands under a different name in my personal ado directory. It might be worthwhile
someday to go through the entire suite and update the code . . .

- Prev by Date:
**st: Floating-point reals, hexadecimal and decimals** - Next by Date:
**Re: st: simulating bernoulli random numbers** - Previous by thread:
**Re: st: simulating bernoulli random numbers** - Next by thread:
**Re: st: simulating bernoulli random numbers** - Index(es):

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