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

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


From   Alexander Tsai <[email protected]>
To   [email protected]
Subject   st: simulating data -- gamma distributed variables with known correlation
Date   Fri, 17 Oct 2003 10:49:51 -0400

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/



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