Basically the same problem that this question contains but in Stata and for integer values. (fastest way to detect if a value is in a set of values in Javascript)
Run the following code in Stata:
set obs 9
generate var1 = 1 in 1
replace var1 = 2 in 2
replace var1 = 3 in 3
replace var1 = 4 in 4
replace var1 = 5 in 5
replace var1 = 6 in 6
replace var1 = 7 in 7 
generate var2 = 6 in 1
replace var2 = 5 in 2
replace var2 = 4 in 3
replace var2 = 3 in 4
replace var2 = 2 in 5
replace var2 = 1 in 6
replace var2 = 58 in 7
replace var2 = 69 in 8
replace var2 = 51 in 9 
The idea is simple. If for example the value 5 (in var1) occurs in the set of all values contained in var2, I want to create var3 and stick a "yes" (in newly created var3) next to the 5 in var1 and "no" otherwise. So for example there would be a "no" (in newly created var3) next to 7 (in var1) because 7 isn't in any of the values contained in var2.
 
     
     
    