Statalist


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

Re: st: Draw new variable with fixed correlation to an existing variable


From   Paulo Guimaraes <[email protected]>
To   [email protected]
Subject   Re: st: Draw new variable with fixed correlation to an existing variable
Date   Wed, 15 Aug 2007 16:07:18 -0400

Rachel,

If you want a new normal variable that on average has, say 0.5 correlation, then you can easily do that:

clear
set obs 10000
local corr=0.5
gen x1=invnorm(uniform())
quietly sum x1
local sz=r(sd)
local mz=r(mean)
local s2=`sz'^2*(1/`corr'^2-1)
gen x2=x1+sqrt(`s2')*invnorm(uniform())
corr x1 x2


Paulo Guimaraes


Rachel wrote:

Suppose I have an existing variable x1, which is distributed as a
standard normal.  I wish to create a new variable x2 (also standard
normal) such that corr(x1,x2)=0.5.  ?Is there a way to do this in
Stata?

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