Hi guys, I'm very new to Stata and very stuck! I am trying to generate an empty matrix (which I have filled with '.' missing values) and then fill it row by row vertically with 18 values generated for 5 categories of a variable in a loop. I have done this by first creating the empty J(5, 18, .) matrix, then running ladder command in a loop to generate the data which is to be stored in the matrix, then generating a matrix from this data (I also wonder if it is better at this stage to make a vector instead of a matrix?), then merging the 2 matrices. However, the new values do not replace the '.' missing values of the empty matrix. My code is as follows:
/////////////////////
matrix varsub_trans_matrix = J(5, 18, .)
foreach var_sub in `var_subs' {
/////////////////////
Is there a different way of merging the matrices to input my newly generated data and replace the missing values, so that the new data is inputted in iterative rows?
In the following step, I plan to then combine the 5 x 18 matrices of 9 different variables in a larger J(45, 18, .) matrix, which I also generated with missing values.
Many thanks for your help!!
/////////////////////
matrix varsub_trans_matrix = J(5, 18, .)
foreach var_sub in `var_subs' {
ladder `var_sub'
matrix `var_sub'_matrix = (r(ident), r(P_ident), r(square), r(P_square), r(cube), r(P_cube), r(sqrt), r(P_sqrt), r(inv), r(P_inv), r(invsq), r(P_invsq), r(invcube), r(P_invcube), r(invsqrt), r(P_invsqrt), r(log), r(P_log))
matrix `var'_matrix = varsub_trans_matrix \ `var_sub'_matrix}
/////////////////////
Is there a different way of merging the matrices to input my newly generated data and replace the missing values, so that the new data is inputted in iterative rows?
In the following step, I plan to then combine the 5 x 18 matrices of 9 different variables in a larger J(45, 18, .) matrix, which I also generated with missing values.
Many thanks for your help!!
Comment