Dear friends,
I’m trying to recode a [r x k] matrix into a new [r x c] matrix of zeros and ones, where the ones are assigned based on conditions about the k columns of the initial matrix. For instance, given a [3x3] matrix [ 1, 0, 3 \ 0, 0, 0 \ 2, 4, 6 ] and the condition of a cell in a new [3x1] matrix being one (1) is that the three previous columns are different from zero for a given row. This would then render a new matrix [ 0 \ 0 \ 1].
I don’t seem to find a “recode” type option for working with matrices. How can one do this? Can it be done in Stata? Or, it needs to be done in Mata?
I’m trying to recode a [r x k] matrix into a new [r x c] matrix of zeros and ones, where the ones are assigned based on conditions about the k columns of the initial matrix. For instance, given a [3x3] matrix [ 1, 0, 3 \ 0, 0, 0 \ 2, 4, 6 ] and the condition of a cell in a new [3x1] matrix being one (1) is that the three previous columns are different from zero for a given row. This would then render a new matrix [ 0 \ 0 \ 1].
I don’t seem to find a “recode” type option for working with matrices. How can one do this? Can it be done in Stata? Or, it needs to be done in Mata?

Comment