Dear all,

I am not new to STATA but I am very new to mata. I have a problem of understanding how to use information of a matrix that I have created in mata to change some of the observations in a stata variable.

I have created a mata matrix now of dimensions 9 x 4 containing string elements that I call

Then a have a larger dataset in stata containing 916 variables and 1416 observations.

I now want to replace some of the instances in one of these variables called

I would like to: replace

What I have managed to do so far is just viewing this

st_sview(Q=.,.,"co_id")

I anticipate that I should do an if else function, but I can't get my head around it.

Any help would be appreciated,

Thanks!

I am not new to STATA but I am very new to mata. I have a problem of understanding how to use information of a matrix that I have created in mata to change some of the observations in a stata variable.

I have created a mata matrix now of dimensions 9 x 4 containing string elements that I call

**E**. It looks as following (example):X1/Y1 | X1 | Y1 | Y1/X1 |

X2/Y2 | X2 | Y2 | Y2/X2 |

X3/Y3 | X3 | Y3 | Y3/Y3 |

X4/Y4 | X4 | Y4 | Y4/X4 |

X5/Y5 | X5 | Y5 | Y5/X5 |

X6/Y6 | X6 | Y6 | Y6/X6 |

X7/Y7 | X7 | Y7 | Y7/X7 |

X8/Y8 | X8 | Y8 | Y8/X8 |

X9/Y9 | X9 | Y9 | Y9/X8 |

I now want to replace some of the instances in one of these variables called

**co_id,**which is the important identifier, based on the conditions set in matrix E (in mata).I would like to: replace

**co_id**with the value of**E[,1] (i.e col 1)**if the value of**co_id**is found in any of the columns 2-4 in matrix**E.**What I have managed to do so far is just viewing this

**co_id**in mata by:st_sview(Q=.,.,"co_id")

I anticipate that I should do an if else function, but I can't get my head around it.

Any help would be appreciated,

Thanks!

## Comment