Dear all,
One of the recurring difficulties I run into when transferring a dataset from Stata to Mata is that the latter does not handle mixed matrices (string and numerical). This is often a problem for me as many datasets that I use contain a string ID. The workaround I rely on in this situation is to (1) encode the ID using something like
(2) save the mapping to the original string IDs into a tempfile; (3) after the Mata analysis, recover those original IDs using a -merge- command.
This works, but I wonder if there are better solutions? For example, would it be possible to load the original string IDs into Mata as a separate string matrix, alongside the matrix holding the numerical data, and somehow keep track of the observation mapping across the two matrices? This would require, I assume, some sort of primary key holding observations together -- possible in Mata?
Thanks for any suggestions,
Charles
One of the recurring difficulties I run into when transferring a dataset from Stata to Mata is that the latter does not handle mixed matrices (string and numerical). This is often a problem for me as many datasets that I use contain a string ID. The workaround I rely on in this situation is to (1) encode the ID using something like
Code:
egen ID_num = group(ID)
This works, but I wonder if there are better solutions? For example, would it be possible to load the original string IDs into Mata as a separate string matrix, alongside the matrix holding the numerical data, and somehow keep track of the observation mapping across the two matrices? This would require, I assume, some sort of primary key holding observations together -- possible in Mata?
Thanks for any suggestions,
Charles
Comment