I have a matrix A that I want to jumble the rows and take the logs of. Then taking the elements on the diagonal and creating a variable in Stata.
![Click image for larger version
Name: Capture.PNG
Views: 1
Size: 19.0 KB
ID: 1405097](filedata/fetch?id=1405097&d=1501865916&type=full)
Tried this bit of code.
mata:
for (i=1; i<=3; i++) {
jumble(A)
logA`i' = log(A)
Ad`i' = diagonal(logA`i')
st_matrix("Ad`i'", Ad`i')
}
end
But it merged all of it into i. I know the code is clunky, but I'm not familiar with loops in Mata.
![Click image for larger version
Name: Capture2.PNG
Views: 1
Size: 55.2 KB
ID: 1405098](filedata/fetch?id=1405098&d=1501866234&type=full)
Thanks, Gene
Tried this bit of code.
mata:
for (i=1; i<=3; i++) {
jumble(A)
logA`i' = log(A)
Ad`i' = diagonal(logA`i')
st_matrix("Ad`i'", Ad`i')
}
end
But it merged all of it into i. I know the code is clunky, but I'm not familiar with loops in Mata.
Thanks, Gene
Comment