Hello all,
I'd like to fill a blank matrix in STATA with 2 columns and 5 rows I found this post from 2011 that suggested (for an 8 by 8 matrix).
so I tried
, which yielded an "invalid syntax error." Perhaps the command has changed and one should use MATA instead?
EDIT: I noticed I was missing the ,. so now I've managed to create the empty matrix and just have to do the rest.
After I have the matrix, I'd like the first column to be a value that I define. For example, in R the code would be:
followed by filling the other columns for different observations (in this case, country years) and then plotting the results of the matrix. Again, the code in R is (where 1:50 refers to the number of observations and 1:5 is the matrix defined above).
What is the best way to do this in STATA? Or do I necessarily have to use MATA instead? I'm not familiar with the latter. Basically, the end result should be 50 graphs, where the y-coordinate corresponds to column 1 in the matrix (and stays the same for each graph) and the x-coordinate corresponds to column 2. I just included the code in R in case it's helpful for explaining what I'm trying to do.
Let me know if this makes sense. Thank you in advance!
I'd like to fill a blank matrix in STATA with 2 columns and 5 rows I found this post from 2011 that suggested (for an 8 by 8 matrix).
Code:
matrix mat1 = J(8,8,.)
Code:
matrix mat1 = J(5,2)
EDIT: I noticed I was missing the ,. so now I've managed to create the empty matrix and just have to do the rest.
After I have the matrix, I'd like the first column to be a value that I define. For example, in R the code would be:
Code:
mat[1, 1] <- log(10) mat[2, 1] <- log(20) mat[3, 1] <- log(30) mat[4, 1] <- log(40) mat[5, 1] <- log(50)
Code:
for (j in 1:50) { for (i in 1:5) { mat[i, 2] <- log(df[j, 1 + i]) } mat <- as.data.frame(mat) plot(mat$V2, mat$V1) }
Let me know if this makes sense. Thank you in advance!
Comment