I want to write a mata function that will take an existing variable X
from the loaded dataset,
multiply it by matrix W that also exist, and create a new stata variable
Y=W*X .
I wrote a code included below which works fine when I substitute my
arguments by real variable names "X" and "Y" but does not want to be
compiled as it is.
mata:
function spatlag(string scalar index, string scalar windex)
{
X=J(0,0,.)
Y=J(0,0,.)
mata matuse L:\FDI\Out\weights2rd
st_addvar("float", windex)
st_view(Y,., windex)
st_view(X,., index)
Y[.,.]=(I(11)#W)*X
}
mata mosave spatlag(), dir(PERSONAL)
end