Dear all,

I am doing a 2000 times monte carlo simulation of two-stage least square estimation with random numbers in Mata with following codes, but I do not know how to extract the esimation results from Mata to Stata. My idea is to stack each estimation result on top of the other and get a varible with 2000 observations. But the code return errors: st_store(): 3200 conformability error
<istmt>: - function returned error
Could anyone help me work this out? Thanks!

Code:
clear all

set obs 2000
gen B_2SLS =.
mata
rseed(435632)

for (i=1; i<=2000; i++){
    R  = (1, 0.5\ 0.5, 1)
    C  = cholesky(R)
    E1 = rnormal(2, 200, 0, 1)'
    E  = E1*C'
    Z1 = rnormal(5, 200, 0, 1)'
    Z  = Z1*I(5)

    P0 = 0.01*J(5, 1, 1)
    B0 = (1)

    X  = Z*P0 + E[., 1]
    Y  = X*B0 + E[., 2]
    P  = Z*luinv(Z'*Z)*Z'

    B_2SLS = (X'*P*Y) / (X'*P*X)

    st_store((strtoreal("i")::strtoreal("i"+"1")), "B_2SLS", B_2SLS)
}
end