Dear Statalisters,

I am trying to do a conditional transformation of a matrix, Specifically, I want a new matrix B that returns 1/x if x>1 and x if x<1

I can do the division just fine, but do not know how to make it conditional on values of x

My question is how can I get Mata to return 1/x for 2 and 5, but just x for .5 and .3? I have a feeling it may have to do with mm_cond, but I could not figure it out.

Thanks for your help!

Michael Howell-Moroney

I am trying to do a conditional transformation of a matrix, Specifically, I want a new matrix B that returns 1/x if x>1 and x if x<1

I can do the division just fine, but do not know how to make it conditional on values of x

Code:

matrix A=(.5, .3\ 2, 5) mata: st_matrix("B", 1 :/ st_matrix("A") ) matrix list B

Thanks for your help!

Michael Howell-Moroney

## Comment