Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Generate two (or more) variables with given within variation, between variation and correlation


From   "Heimsch Fabian" <heimschf@ethz.ch>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Generate two (or more) variables with given within variation, between variation and correlation
Date   Sun, 20 May 2012 12:34:54 +0000

Dear all

My problem is that I want to generate random variables for panel data. E.g. two variables x and y should each have a distinct and predefined between variation, within variation and predefined correlation. 

So far, I tried to randomly draw variables x and y, to stack it according to the panel structure with respect to the number of panel units and time periods. The problem (of course) is that the correlation is always close to zero. How can I do this to achieve any given level of correlation?

I tried to program something like

xtgenvar xname mx sbx swx yname my sby swy rho

where xname would be the name of the variable x, mx the mean, sbx the between variation, swx the within variation. The same holds for the variable y and rho is the desired correlation. 

Help Is much appreciated, many thanks

Fabian



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index