Hello,

I am trying to edit a spatial weighting matrix created by the spmatrix create command in Stata. I would like to replace all the non-zero entries (>0) with 1, but this seems to not be working.

I have the following code to do so, where spatial_weights is a weighting matrix created with spmatrix create:
Code:
spmatrix matafromsp W id = spatial_weights

mata:
    for (i=1; i<=rows(W); i++) {
        for (j=1; j<=cols(W); j++) {
            if (W[i,j]:>0) W[i,j]=1
        }
    }
end

spmatrix spfrommata spatial_weights = W id, replace
What I get as a result is a matrix of indeed same entries for all the previously non-zero entries, but they all take the value of .01065647570978. Any ideas of what am I doing wrong?