I would have one DX variable and a categorical variable that indicates which DX, in the dataset with DX1-DX40 (in other words, the data will be in long layout). Then on my criteria dataset, each criterion will be associated with a list of variables and I would name this variable "DX" and the associated variable "var" (this in long layout too). Once I execute a many-to-one merge, I will be able to link each var with a DX. The search will be as simple as:
However, I do not know how you want to use this data, so if the locals work for you, then you can use them. In general, analysis in Stata is more efficient with data in long layout.
Code:
browse DX which if var=="nstemi"
Comment