**[D] drawnorm** -- Draw sample from multivariate normal distribution

__Syntax__

**drawnorm** *newvarlist* [**,** *options*]

*options* Description
-------------------------------------------------------------------------
Main
**clear** replace the current dataset
__d__**ouble** generate variable type as **double**; default is
**float**
**n(***#***)** generate *#* observations; default is current
number
__sd__**s(***vector***)** standard deviations of generated variables
**corr(***matrix*|*vector***)** correlation matrix
**cov(***matrix*|*vector***)** covariance matrix
__cs__**torage(**__f__**ull)** store correlation/covariance structure as a
symmetric k*k matrix
__cs__**torage(**__l__**ower)** store correlation/covariance structure as a lower
triangular matrix
__cs__**torage(**__u__**pper)** store correlation/covariance structure as an
upper triangular matrix
**forcepsd** force the covariance/correlation matrix to be
positive semidefinite
__m__**eans(***vector***)** means of generated variables; default is **means(0)**

Options
**seed(***#***)** seed for random-number generator
-------------------------------------------------------------------------

__Menu__

**Data > Create or change data > Other variable-creation commands >** **Draw**
**sample from normal distribution**

__Description__

**drawnorm** draws a sample from a multivariate normal distribution with
desired means and covariance matrix. The default is orthogonal data with
mean 0 and variance 1. The covariance matrix may be singular. The
values generated are a function of the current random-number seed or the
number specified with **set seed()**; see **[R] set seed**.

__Options__

+------+
----+ Main +-------------------------------------------------------------

**clear** specifies that the dataset in memory be replaced, even though the
current dataset has not been saved on disk.

**double** specifies that the new variables be stored as Stata **double**s,
meaning 8-byte reals. If **double** is not specified, variables are
stored as **float**s, meaning 4-byte reals. See **[D] data types**.

**n(***#***)** specifies the number of observations to be generated. The default
is the current number of observations. If **n(***#***)** is not specified or
is the same as the current number of observations, **drawnorm** adds the
new variables to the existing dataset; otherwise, **drawnorm** replaces
the data in memory.

**sds(***vector***)** specifies the standard deviations of the generated variables.
**sds()** may not be specified with **cov()**.

**corr(***matrix*|*vector***)** specifies the correlation matrix. If neither **corr()**
nor **cov()** is specified, the default is orthogonal data.

**cov(***matrix*|*vector***)** specifies the covariance matrix. If neither **cov()** nor
**corr()** is specified, the default is orthogonal data.

**cstorage(full**|**lower**|**upper)** specifies the storage mode for the correlation
or covariance structure in **corr()** or **cov()**. The following storage
modes are supported:

**full** specifies that the correlation or covariance structure is stored
(recorded) as a symmetric k*k matrix.

**lower** specifies that the correlation or covariance structure is
recorded as a lower triangular matrix. With k variables, the
matrix should have k(k+1)/2 elements in the following order:

C(11) C(21) C(22) C(31) C(32) C(33) ... C(k1) C(k2) ... C(kk)

**upper** specifies that the correlation or covariance structure is
recorded as an upper triangular matrix. With k variables, the
matrix should have k(k+1)/2 elements in the following order:

C(11) C(12) C(13) ... C(1k) C(22) C(23) ... C(2k) ...
C(k-1k-1) C(k-1k) C(kk)

Specifying **cstorage(full)** is optional if the matrix is square.
**cstorage(lower)** or **cstorage(upper)** is required for the vectorized
storage methods. See storage modes for examples.

**forcepsd** modifies the matrix C to be positive semidefinite (psd), and so
be a proper covariance matrix. If C is not positive semidefinite, it
will have negative eigenvalues. By setting negative eigenvalues to 0
and reconstructing, we obtain the least-squares positive-semidefinite
approximation to C. This approximation is a singular covariance
matrix.

**means(***vector***)** specifies the means of the generated variables. The
default is **means(0)**.

+---------+
----+ Options +----------------------------------------------------------

**seed(***#***)** specifies the initial value of the random-number seed used by the
**runiform()** function. The default is the current random-number seed.
Specifying **seed(***#***)** is the same as typing **set seed** *#* before issuing
the **drawnorm** command.

__Examples__

Generate 2,000 independent observations (**x**,**y**); **x** with mean 2 and standard
deviation .5; **y** with mean 3 and standard deviation 2

**. matrix m = (2,3)**
**. matrix sd = (.5,2)**
**. drawnorm x y, n(2000) means(m) sds(sd)**
**. summarize**

Draw a sample of 1,000 observations from a bivariate standard normal
distribution, with correlation 0.5

**. clear**
**. matrix C = (1, .5 \ .5, 1)**
**. drawnorm x y, n(1000) corr(C)**
**. summarize**

Equivalently,

**. clear**
**. matrix C = (1, .5, 1)**
**. drawnorm x y, n(1000) corr(C) cstorage(lower)**
**. summarize**