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

From |
"Austin Nichols" <austinnichols@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Wed, 15 Aug 2007 18:32:30 -0400 |

Rachel-- If I understand correctly, you want the new variable(s) to have *exactly* the specified correlation structure, like -corr2data- instead of -drawnorm- for new variables? I thought -corr2data- might do this for you, but it does not: clear set obs 100 set seed 12345 matrix r=(1, .5 ,.5 \ .5, 1, .5 \ .5, .5 ,1) corr2data x1 x2 x3, corr(r) corr x* more clear set obs 100 set seed 12345 matrix r=(1, .5 ,.5 \ .5, 1, .5 \ .5, .5 ,1) mat rown r = x1 x2 x3 mat coln r = x1 x2 x3 g x1=invnorm(uniform()) corr2data x2 x3, corr(r) corr x* I think -corr2data- should probably exit with an error in the second piece of the above code, since it cannot generate two variables with the desired correlations. On 8/15/07, Paulo Guimaraes <guimaraes@moore.sc.edu> wrote: > 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? * * 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/

**References**:**st: Draw new variable with fixed correlation to an existing variable***From:*Rachel <academicgirl@gmail.com>

**Re: st: Draw new variable with fixed correlation to an existing variable***From:*Paulo Guimaraes <guimaraes@moore.sc.edu>

- Prev by Date:
**Re: st: Drawing multiple variables with fixed correlations to an existing variable and to each other** - Next by Date:
**Re: st: lcolor not allowed** - Previous by thread:
**Re: st: Draw new variable with fixed correlation to an existing variable** - Next by thread:
**Re: st: Draw new variable with fixed correlation to an existing variable** - Index(es):

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