Dear Stata users,
I have a question on associative arrays in mata.
Let’s assume I have an array called dX composed of 4 matrices X1, X2, X3 and X4 (each of dimensions nxn). Let’s call these the layers of the array. If I want to change element (i,j) in layer k by value z, I would do the following
1. W=asarray(dX,k)
2. W[i,j]=z
3.asarray(dX,k,W)
In step 1 I would obviously recover matrix Xk for the first iteration but after a first round of changes it will not be matrix Xk anymore.
in step 2 I change the element of interest with the wanted value
in step 3 I replace layer k with my new matrix W
I know that we can access element (i,j) of layer k in array dX by typing “asarray(dX,k)[1,1]”. Unfortunately typing “asarray(dX,k)[1,1]=z” would not work.
I am pretty sure that my way of proceeding is not efficient, but I did not find any better way up to now.
Any help would be appreciated
All the best
Vincenzo
I have a question on associative arrays in mata.
Let’s assume I have an array called dX composed of 4 matrices X1, X2, X3 and X4 (each of dimensions nxn). Let’s call these the layers of the array. If I want to change element (i,j) in layer k by value z, I would do the following
1. W=asarray(dX,k)
2. W[i,j]=z
3.asarray(dX,k,W)
In step 1 I would obviously recover matrix Xk for the first iteration but after a first round of changes it will not be matrix Xk anymore.
in step 2 I change the element of interest with the wanted value
in step 3 I replace layer k with my new matrix W
I know that we can access element (i,j) of layer k in array dX by typing “asarray(dX,k)[1,1]”. Unfortunately typing “asarray(dX,k)[1,1]=z” would not work.
I am pretty sure that my way of proceeding is not efficient, but I did not find any better way up to now.
Any help would be appreciated
All the best
Vincenzo
Comment