Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: simulating data -- gamma distributed variables with known correlation


From   "FEIVESON, ALAN H. (AL) (JSC-SK) (NASA)" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: simulating data -- gamma distributed variables with known correlation
Date   Fri, 17 Oct 2003 11:11:49 -0500

Alexander - One way of generating correlated random variables with
non-normal marginal distributions is to use the method of copulas - see my
mention of this in the Stata Jouirnal, Vol. 2 No. 2 p. 117.

In general, the idea is to first simulate correlated Normal RV's using the
Cholesky decomposition - then transform to dependent uniform RV's using the
normal CDF transformation - then to transform again to the desired
distribution - in your case using an inverse Gamma CDF transformation.

The method will work for any number of variables, but in general the
magnitude of the correlations you get will be less than the magnitudes of
the original (normal) correlations. Thus you may have to start with higher
coorelations to achieve the ones you desire. Again, refer to what I did in
the STata Journal article for the Weibull distribution.

Incidentally, what you did does not appear correct to me. It looks as though
you tried to generate gamma-distributed RV's by using the gamma density
instead of the inverse gamma CDF. However even if your e's were really
distributed as gamma, there is another error. "hd" won't be distributed as a
gamma RV because it's a linear combination of e1 and e2. In general, a
linear combnation of two gamma RV's does not itself have a gamma
distribution.

The linear combinations must be computed while the RV's are still normal -
THEN transform to gammas.


Al Feiveson



-----Original Message-----
From: Alexander Tsai [mailto:[email protected]]
Sent: Friday, October 17, 2003 9:50 AM
To: [email protected]
Subject: st: simulating data -- gamma distributed variables with known
correlation


Dear Statalisters,

I am trying to generate four gamma-distributed variables with the
following correlation structure:

    s  hd   q   b
s   1  .8  .8  .6
hd .8   1  .8  .8
q  .8  .8   1  .8
b  .6  .8  .8   1

So far I have only been able to figure out how to generate how to
generate two variables (s,hd) with the desired correlation.

    s  hd
s   1  .8
hd .8   1

I have copied my code for the two variables below. Does anyone have
suggestions for how to accomplish what I would like to do for the four
variables?

set obs 1000
generate c1=gammaden(.5,1,0,uniform())
generate c2=gammaden(.5,1,0,uniform())
matrix A=(1,.8\.8,1)
matrix T=cholesky(A)
local e1=T[2,1]
local e2=T[2,2]
generate s=c1
generate hd=`e1'*c1+`e2'*c2

Thank you,
Alex



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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