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
0 Response to Changing matrix entries to 1
Post a Comment