Hello everyone,
I would like to warn you that I am new to mata and that I have some problems with the way loops work, more precisely with the way to refer to matrices.
All my matrices are currently on mata and look like this:
I have 52*21 int_i_j matrices where i=1...51 and j=1994...2014 and 51 WI_i matrices where i=1...51. i represents countries and j represents years.
What I would like to do is to multiply each int_i_j matrix by the corresponding WI matrix, i.e. the i in the int_i_j matrix and the i in the WI_i matrix must be equal. The code I did initially looks like this:
mata
for(i=1;i<=51;i++) {
for(j=1994;j<=2014;k++) {
"wgt_int_`i'_`j'=WI_`i' * int_`i'_`j'
}
}
end
wgt_int_`i'_`j' is the name I want to give to my new matrices created by multiplying the others.
I understand that mata doesn't work like Stata and that I can't refer to the running variable in the same way (using `...'), but I can't find anywhere how to do this loop on mata.
I would like to know if it is possible to do it and how if anyone knows.
Thanks.
Best regards,
DS
I would like to warn you that I am new to mata and that I have some problems with the way loops work, more precisely with the way to refer to matrices.
All my matrices are currently on mata and look like this:
I have 52*21 int_i_j matrices where i=1...51 and j=1994...2014 and 51 WI_i matrices where i=1...51. i represents countries and j represents years.
What I would like to do is to multiply each int_i_j matrix by the corresponding WI matrix, i.e. the i in the int_i_j matrix and the i in the WI_i matrix must be equal. The code I did initially looks like this:
mata
for(i=1;i<=51;i++) {
for(j=1994;j<=2014;k++) {
"wgt_int_`i'_`j'=WI_`i' * int_`i'_`j'
}
}
end
wgt_int_`i'_`j' is the name I want to give to my new matrices created by multiplying the others.
I understand that mata doesn't work like Stata and that I can't refer to the running variable in the same way (using `...'), but I can't find anywhere how to do this loop on mata.
I would like to know if it is possible to do it and how if anyone knows.
Thanks.
Best regards,
DS
Comment