I am very new to mata and ran to a problem which I could not figure out.
I am trying to implement matrix function.
I have a matrix b (a 1X9 matrix) and matrix v (a 9X9 matrix). I am required to:
Randomly draw (5000 draws) from standard normal distribution a vector x with 9 independent elements (x is a 5000 X9 matrix).
Calculate Z such that Z = b' + c'x, (where c = cholesky (v))
Finally, generate matrix "a" such that a = Z/0.0311
I am failing to get past the Z matrix. I am only able to implement this calculation if I keep the dimensions of x to 9X9.
Here the part of my code that is at least running.
mat b = [1.0599, 0.1580, 0.5303, 0.0518, -0.0144, -0.0787, -0.1104, -0.1413, 0.0489]
mat v = [0.0034, 0.0056, -0.0003, -0.0004, -0.0003, -0.0004, -0.0001, -0.0003, 0 ///
\0.0056, 0.0111, -0.0003, -0.0006, -0.0005, -0.0008, -0.0001, -0.0006, 0.0001 ///
\-0.0003, -0.0003, 0.018, 0.0008, 0, 0, 0, 0, 0 ///
\-0.0004, -0.0006, 0.0008, 0.0147, 0, 0, 0, 0, 0 ///
\-0.0003, -0.0005, 0, 0, 0.0068, 0.0002, 0, 0, 0 ///
\-0.0004, -0.0008, 0, 0, 0.0002, 0.0063, 0, 0, 0.0001 ///
\-0.0001, -0.0001, 0, 0, 0, 0, 0.0041, 0.0002, 0 ///
\-0.0003, -0.0006, 0, 0, 0, 0, 0.0002, 0.0044, 0 ///
\0, 0.0001, 0, 0, 0, 0.0001, 0, 0, 0.0065]
mat c = cholesky(v)
set obs 5000
forvalues i=1/9 {
gen x`i'=rnormal(0,1)
}
I am trying to implement matrix function.
I have a matrix b (a 1X9 matrix) and matrix v (a 9X9 matrix). I am required to:
Randomly draw (5000 draws) from standard normal distribution a vector x with 9 independent elements (x is a 5000 X9 matrix).
Calculate Z such that Z = b' + c'x, (where c = cholesky (v))
Finally, generate matrix "a" such that a = Z/0.0311
I am failing to get past the Z matrix. I am only able to implement this calculation if I keep the dimensions of x to 9X9.
Here the part of my code that is at least running.
mat b = [1.0599, 0.1580, 0.5303, 0.0518, -0.0144, -0.0787, -0.1104, -0.1413, 0.0489]
mat v = [0.0034, 0.0056, -0.0003, -0.0004, -0.0003, -0.0004, -0.0001, -0.0003, 0 ///
\0.0056, 0.0111, -0.0003, -0.0006, -0.0005, -0.0008, -0.0001, -0.0006, 0.0001 ///
\-0.0003, -0.0003, 0.018, 0.0008, 0, 0, 0, 0, 0 ///
\-0.0004, -0.0006, 0.0008, 0.0147, 0, 0, 0, 0, 0 ///
\-0.0003, -0.0005, 0, 0, 0.0068, 0.0002, 0, 0, 0 ///
\-0.0004, -0.0008, 0, 0, 0.0002, 0.0063, 0, 0, 0.0001 ///
\-0.0001, -0.0001, 0, 0, 0, 0, 0.0041, 0.0002, 0 ///
\-0.0003, -0.0006, 0, 0, 0, 0, 0.0002, 0.0044, 0 ///
\0, 0.0001, 0, 0, 0, 0.0001, 0, 0, 0.0065]
mat c = cholesky(v)
set obs 5000
forvalues i=1/9 {
gen x`i'=rnormal(0,1)
}
Comment