Code:
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*
I'm in a similar situation, except I need to simulate a single variable with a pre-specified correlation to two existing variables. Is it possible to modify the mata code to handle that scenario?
IYH
0 Response to Generating a new variable with a pre-specified correlation to two existing variables
Post a Comment