.-
help for ^gennorm^                              @net:from http://www.stata.com/users/wgould!http://www.stata.com/users/wgould@
.-

Generate correlated normal, random deviates
-------------------------------------------

	^gennorm^ newvarname [^if^ exp] [^in^ range]

	^gennorm^ newvarlist [^if^ exp] [^in^ range]^, c^orr^(^name|# # ... #^)^


Description
-----------

^gennorm^ generates correlated normal, random deviates.  The values generated
are a function of the current random-number seed; see help @generate@.


Options
-------

^corr(^name|# # ... #^)^ specifies the correlation.  The option is required if two
    or more new variables are being benerated and not allowed if one new
    variable is being generated. 

    ^corr(^name^)^ specifies the name of a matrix that is to be used as the 
    correlation matrix.

    ^corr(^# # ... #^)^ specifies the correlations themselves.  Correlations are
    to be listed in the order 

		variable 1 with variable 2
		variable 1 with variable 3
		variable 1 with variable 4
		...
		variable 2 with variable 3
		variable 2 with variable 4
		...
		variable n-1 with variable n


Remarks
-------

One random deviate
------------------

The first syntax creates one N(0,1) variable and typing

	. ^gennorm z^

is no different from typing 

	. ^generate z = invnorm(uniform())^

If you want to generate z as a double, type 

	. ^gennorm double z^


Two random deviates
-------------------

Use the second syntax when you wish to create two or more correlated deviates.
Typing 

	. ^gennorm a b, corr(.2)^

creates a and b with values drawn from a N(0,1) distribution with correlation
0.2 or, more correctly, a N(0,S) distribution where S is the matrix

               +-        -+
         S =   |   1      |             (S is symmetric)
               |  .2   1  |
               +-        -+

If you want to generate a and b as doubles, type 

	. ^gennorm double(a b), corr(.2)^


Three or more random deviates
-----------------------------

Typing

	. ^gennorm a b c, corr(.2 .3 .4)^

creates a, b, and c with value draw from a N(0,S) distribution where

               +-            -+
               |   1          |
          S =  |  .2    1     |
               |  .3   .4   1 |
               +-            -+

That is, corr(a,b)=.2, corr(a,c)=.3, and corr(b,c)=.4


Example
-------

    . ^set obs 1000^
    obs was 0, now 1000

    . ^set seed 1234^

    . ^gennorm a b c, corr(.2 .3 .4)^

    . ^summarize a b c^

    Variable |     Obs        Mean   Std. Dev.       Min        Max
    ---------+-----------------------------------------------------
           a |    1000   -.0479536   1.000777  -3.386151   3.021003  
           b |    1000   -.0223123    1.00848  -3.428211   2.678686  
           c |    1000   -.0556631   1.021435   -3.38529   3.542448  

    . ^correlate a b c^
    (obs=1000)

             |        a        b        c
    ---------+---------------------------
           a |   1.0000
           b |   0.2018   1.0000
           c |   0.2748   0.3737   1.0000


Methods and formulas
--------------------

Let y1, y2, ..., yk be the variables to be created.  Let P be the desired
correlation (covariance) matrix.

Define Y = (y1, y2, ..., yk) as the data matrix to be created.  ^gennorm^ begins
by creating k orthogonal, normal random deviates C = (c1, c2, ..., ck) and
then calculates Y = cholesky(P)*C.


Author
------

William Gould, Stata Corporation.
Statalist distribution, 02feb1999.


Also see
--------

   FAQS:  @browser:http://www.stata.com/support/faqs/stat/mvnorm.html!http://www.stata.com/support/faqs/stat/mvnorm.html@
On-line:  help for @generate@
