Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • make indicator matrix in mata

    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

  • #2
    Cross-posted. Answered within http://www.statalist.org/forums/foru...matrix-in-mata

    Comment

    Working...
    X