Hi all,

I have a question about comparing two string variables. I wanted to compare the values of these variables row by row, to see if they contain any same elements. That is to say, for each row, they do not need to be exactly the same. As long as they have at least one same element, then the dummy variable indicating same elements should be 1 (it would be better if the number of same elements can be reported). For example, for the first row, if the value of var1 is A,B, and the value of var2 is A,B,D. Then, the value of the dummy variable is 1 since they have two same elements, A and B. How can I realize this using STATA?

Thanks for your answer in advance!

Best,
Yongli