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

# Re: st: random number generator for gamma

 From Scott Merryman To statalist@hsphsun2.harvard.edu Subject Re: st: random number generator for gamma Date Wed, 29 Sep 2010 10:25:17 -0500

```The mean of a gamma distribution  = shape*scale.

In the rndgamx syntax the scale is calculated as mu*shape.

With m=2  -rndgamx  m , s(11.11)- should produce of mean of 22.22*11.11 = 246.86

If you want a mean of 2 with a shape parameter of 11.11 then mu = 2/(11.11)^2 :

. clear

. set obs 10000
obs was 0, now 10000

. gen y = 2/(11.11)^2

. rndgamx  y  , s(11.11)
( Generating ............ )
Variable xg created.

. sum

Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
y |     10000    .0162032           0   .0162032   .0162032
xg |     10000    2.001865    .5960008     .40838   4.753399

Scott

On Wed, Sep 29, 2010 at 7:48 AM, Tomas Lind <tomas.lind@ki.se> wrote:
> Dear Statalist
>
> I“ve been using the -rnd- ado-package from Hilbe/Linde-Zwirble (update from
> STB-28: sg44).
>
> The following syntax produces sensible results (mean and sd) when I generate
> 20000 Gamma distributed random numbers with shape=11.11 and scale=0.18
>
> clear *
> rndgam 20000 11.11  0.18
> summarize xg    // mean=2.0 sd=0.60
>
>
>
> However, with -rndgamx- I don“t get the same values. I have probably missed
> something fundamental. Someone know what goes on?
>
> clear *
> set obs 20000
> gen m=2         // mean=2
> rndgamx  m , s(11.11)
> summarize xg    // mean=247 sd=74
>
>
> /Tomas

*
*   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/
```