1
votes

Hi I need help in Stata's Mata programming language for the following Minimum Working Example.

I am trying to insert sub-matrices of dimension (1x200) (generated by a random normal draw) inside a pointer matrix of dimension 600x1 (V matrix).

mata:
T=600     //number of markets
K_S=1    //number of variables with stochastic coefficients
R=200   //number of random draws
st_matrix("T", T)
//pointers to the market specific random draws:
V=J(T,1,NULL)   //   T by 1  0 matrix

for(t=1;t<=T;t++){ 
V[t]=(rnormal(K_S,R,0,1)) //dimension K_S x R
}
end

The problem is I am getting a "rnormal(): 3200 conformability error"

Could you suggest what I am doing wrong.

Thanks

1
I can't get past st_matrix("T", 600) in your case, which creates a matrix in Stata (NB) which is 1 x 1 and holds the constant 600. What is the point of that? This looks like the XY problem to me. Do you need a matrix that is 600 x 200 at any one time? If so, why not produce it directly? Why are pointers needed? xyproblem.info - Nick Cox

1 Answers

1
votes

You are trying to assign a K_S x R matrix to a single cell in a column vector. A pointer has to be assigned, well, a pointer:

mata:
T   = 600 // number of markets
K_S = 1   // number of variables with stochastic coefficients
R   = 200 // number of random draws
st_matrix("T", T)

// pointers to the market specific random draws:
V = J(T, 1, NULL)  // T by 1  0 matrix

for(t=1; t<=T; t++){ 
    V[t]= &(rnormal(K_S, R, 0, 1)) //dimension K_S x R
}
end

In mata the & notation means pointer.