Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72762

make indicator matrix in mata

$
0
0
Hi, i want to make a 0/1 matrix in mata based on some other matrix (in my example W) based on value of each element, so if it is greater than some value element should be 1 and otherwise 0.I can make it by loops as below but is there some command that already does this in shorter way?Thanks!

mata:
n = rows(W)

for (i=1; i<=n; i++){
for (j=1; j<=n; j++){
if (W[i,j]>2) W[i,j] = 1
else W[i,j] = 0
}
}
end

Viewing all articles
Browse latest Browse all 72762

Trending Articles