Dear Statalist,
I have a matrix A with zeros on the diagonal and non-zero, positive numbers off the diagonal. Can anyone suggest a way to identify the smallest non-zero (i.e., off-diagonal) number in A?
I can find the largest number with:
mata: st_matrix("max", max(st_matrix("A")))
To find the smallest value, I thought I would use the mata function _diag() to replace the elements on the diagonal with a number so large it would not appear elsewhere:
mata: A2=_diag(st_matrix("A"),9)
mata: A2
mata: st_matrix("min", min(A2))
Unfortunately, my mata skills are minimal, and the code above does not even appear to make the matrix A2. Perhaps there is an easy way to do this without even using mata?
Thanks,
Jeremy
I have a matrix A with zeros on the diagonal and non-zero, positive numbers off the diagonal. Can anyone suggest a way to identify the smallest non-zero (i.e., off-diagonal) number in A?
I can find the largest number with:
mata: st_matrix("max", max(st_matrix("A")))
To find the smallest value, I thought I would use the mata function _diag() to replace the elements on the diagonal with a number so large it would not appear elsewhere:
mata: A2=_diag(st_matrix("A"),9)
mata: A2
mata: st_matrix("min", min(A2))
Unfortunately, my mata skills are minimal, and the code above does not even appear to make the matrix A2. Perhaps there is an easy way to do this without even using mata?
Thanks,
Jeremy
Comment