Dear stata users:
I always enjoy looking this forum and learn a lots!
Let me ask the question I have today.
I have several matrices from years 2003-2016 named as:
W_2003, X_2003, …, W_2016, X_2016.
“W_”s are spatial weight matrices and matrices “X_” include variables related to the place.
I would like to make products WX for each year.
Following is the mock example of my code:
/*** mata function ***/
mata
void wx(string matrix A, string matrix B) {
A_mat = st_matrix(“A”)
B_mat = st_matrix(“B”)
AB_mat = A_mat*B_mat
st_matrix("AB_mat", AB_mat)
}
end
/*** stata session****/
/* matrices W_2003, X_2003, … are already defined as “matrix” in the stata */
forvalues Y=2003/2016 {
mata: wx(“W_`Y’”, “X_`Y’”)
}
However, this code did not work and following errors/notes appeared:
note: argument A unused
note: argument B unused
I suppose I probably have problems of passing the matrices to my Mata function, wx.
Although I know there are several similar questions had already been posted,
I couldn’t find the cases using matrices for arguments as far as I know.
Could anyone suggest remedies to deal with the problem?
Thanks in advance.
Kazuto
I always enjoy looking this forum and learn a lots!
Let me ask the question I have today.
I have several matrices from years 2003-2016 named as:
W_2003, X_2003, …, W_2016, X_2016.
“W_”s are spatial weight matrices and matrices “X_” include variables related to the place.
I would like to make products WX for each year.
Following is the mock example of my code:
/*** mata function ***/
mata
void wx(string matrix A, string matrix B) {
A_mat = st_matrix(“A”)
B_mat = st_matrix(“B”)
AB_mat = A_mat*B_mat
st_matrix("AB_mat", AB_mat)
}
end
/*** stata session****/
/* matrices W_2003, X_2003, … are already defined as “matrix” in the stata */
forvalues Y=2003/2016 {
mata: wx(“W_`Y’”, “X_`Y’”)
}
However, this code did not work and following errors/notes appeared:
note: argument A unused
note: argument B unused
I suppose I probably have problems of passing the matrices to my Mata function, wx.
Although I know there are several similar questions had already been posted,
I couldn’t find the cases using matrices for arguments as far as I know.
Could anyone suggest remedies to deal with the problem?
Thanks in advance.
Kazuto
Comment