On Mon, 11 Jan 2010, Sven Schreiber wrote:
Lars Pålsson-Syll schrieb:
> Hi,
> Trying to replicate a Monte Carlo simulation in Hill/Griffiths/LIm "Principles
of econometrics" (3rd ed, p 273)
> I run in to problem when in my script trying to incorporate that the population
correlation between the x-values and
> the error-values should be 0.6. Could anyone help me?
> Best regards,
> Lars
If your question is how to produce (pseudo-) random series with the
needed correlation structure, then create two independent series and
multiply that vector (actually 2-col data matrix) with an appropriate
matrix (cholesky factor of the wanted covariance matrix).
An example:
<script>
scalar N = 100000
nulldata N --preserve
scalar r = 0.6
matrix X = mnormal(N, 2)
matrix V = {1, r; r, 1}
matrix C = cholesky(V)
X *= C' # note: use the transpose
series x1 = X[,1]
series x2 = X[,2]
r = corr(x1, x2)
</script>
Allin Cottrell