Statalist


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

Re: st: Drawing multiple variables with fixed correlations to an existing variable and to each other


From   "Scott Merryman" <[email protected]>
To   [email protected]
Subject   Re: st: Drawing multiple variables with fixed correlations to an existing variable and to each other
Date   Wed, 15 Aug 2007 17:25:37 -0500

clear

matrix C = (1, 0, 0\0, 1, 0\0, 0, 1)
corr2data x1 x2 x3, n(100) corr(C) clear

//Impose correlations:
//corr(x1,x2)=.25
//corr(x1,x3)=.33
//corr(x2,x3)=.75

mata
	P =(1, .25, .33\.25, 1 , .75 \ .33, .75 , 1)
	A = cholesky(P)
	X= st_data( ., .)
	R = X*A'
	corr = correlation(R,1)
	st_matrix ("corr", corr)
	st_matrix ("R", R)
end
svmat R
corr R*


Scott


On 8/15/07, Rachel <[email protected]> wrote:
> Hi Mike,
>
> The issue with drawnorm is that it draws all the variables at once.  I
> need to draw a set of variables with a fixed correlation structure
> relative to an EXISTING variable.
>
> Thanks,
> Rachel
*
*   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