Announcement

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

  • Conditional sum of each row

    Dear stata users,

    I have a (4915,4915) matrix and I want to calculate the sum of each row, except the diagonal. I also could do it using the command generate rowtotal but since I don't want to sum all the values in this row, I think it is better to use mata.

    To make things clear, lets say I have this matrix and I want the following vector as a result:

    3 4 5 9
    6 7 8 -> 14
    9 10 11 19

    I only want to sum the entries of the row, where the row is not equal to the column.
    Hence, I would like to build a matrix based on the previous one, where the diagonal consists of zeros:

    0 4 5 9
    6 0 8 -> 14
    9 10 0 19

    How can I do that??
    Many thanks for your help.

    Anja
Working...
X