# st: RE: Generating random variates

 From "Steichen, Thomas" To Subject st: RE: Generating random variates Date Thu, 22 Aug 2002 16:11:25 -0400

```anirban basu writes:
> I was wondering if there is any easy way to generate random
> variates for
> Poisson, Negative Binomial and Inverse Gaussian distributions  where
> E(y) = mu = exp(xb) in Stata. Thanks,

Check out:

STB-41  sg44.1 . . . . . . . . . . . .  Correction to random number generators
(help rnd if installed)  . . . . . . . . J. Hilbe and W. Linde-Zwirble
1/98    p.23; STB Reprints Vol 7, p.166
faster version plus minor changes

Here is part of the help file:

help for random number generators                update from STB-28: sg44
.-                                                    Hilbe/Linde-Zwirble

Current as of 28Jan1999
Random number generators
------------------------

[noncentral] Student's t:   rndt obs df [delta]
Example: rndt 10000 10
rndt 10000 10 3

[noncentral] Chi-square:   rndchi obs df [lambda]
Example: rndchi 10000 4
rndchi 10000 4 3

[noncentral] F:   rndf obs df_numer df_denom [lambda]
Example: rndf 10000 4 15
rndf 10000 4 15 3

log normal:   rndlgn obs mean stddev
Example: rndlgn 10000 0 0.5

Poisson:   rndpoi obs mean
rndpoix [ mu ]
Example: rndpoi 10000 4
rndpoix mu

Poisson:   rndpod obs mean dispersion
(ovedispersed)   rndpodx [mu], s(#)
Example: rndpod 10000 4 1.2
rndpodx mu, s(1.2)

binomial:   rndbin obs prob numb
rndbinx [ prob ] den
Example: rndbin 10000 0.5 1
rndbinx mu den
Note: mu = variable with p values
den = case denominator (1=binary)

negative binomial:   rndnbx [mu] , k(#)
Example: rndnblx mu, k(0.5)

Gamma:   rndgam obs shape scale
rndgamx [mu], s(#)
Example: rndgam 10000 4 2
rndgamx mu, s(1)
Note: s(1) specifies a shape parameter of 1;
the scale is calculated from mu*shape

inverse Gaussian:   rndivg obs mean sigma
rndivgx [mu], s(#)
Example: rndivg 10000 10 0.05
rndivgx mu, s(0.05)
Note: mu = 1/sqrt(eta)
variance = sigma^2*mu*3

exponential:   rndexp obs shape
Example: rndexp 10000 3

Weibull:   rndwei obs shape scale
Example: rndwei 10000 3 2

Beta binomial:   rndbb obs denom prob k
Example: 10000 200 0.2 0.05
Note: prob= p = a1/(a1+a2)
k = dispersion = 1/(a1+a2+1)

Generalized logistic:   rndglog obs L A T
(3 parameter)     Example: rndglog 10000 3.0 0.7 4.5
Note: L = (long) right hand tail
A = (alpha) left hand tail
T = (time) position parameter
Based on Fit-Meister (W. Linde-Zwirble)

```
```CONFIDENTIALITY NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information.  If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system.  Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

```