Hi,
In the original dataset, var1 would have more than 200K values and var2 have more than 14K values (all strings).
I want Stata to remember the string values of var2 and check if there is any occasion where there is a match in var1 then create a dummy variable and assign value of 1 to it. I tried the following:
But for some reason this does not work in terms of results.
Is there anyway around to achieve it? I also tried egen any match but it says in the error msg that var1 is a string variable and cannot be included in the varlist!
In the original dataset, var1 would have more than 200K values and var2 have more than 14K values (all strings).
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str4 var1 str5 var2 "R560" "A00 " "T393" "A000 " "J219" "A001 " "P59" "A009 " "K092" "A01 " "R509" "A010 " "G379" "A011 " "A162" "A012 " "P073" "A013 " "F209" "A014 " "Z523" "A02 " "C169" "K092 " "H663" "A021 " "S835" "A022 " "Z501" "A028 " "B209" "A029 " "F192" "A03 " "D414" "A030 " "C419" "A031 " "J039" "A032 " "U071" "A033 " "Z000" "A038 " "G129" "A039 " "J189" "A04 " "E14" "A040 " "K810" "A041 " "R560" "A042 " "G060" "A043 " "G473" "A044 " "P073" "A045 " "F209" "A046 " "D70" "A047 " "C719" "A048 " "L021" "A049 " "M659" "A05 " "Z501" "A050 " "A527" "A051 " "F151" "A052 " "N270" "A053 " "C910" "A054 " "U071" "A058 " "U071" "A059 " "K297" "A162 " "Z922" "A060 " "J219" "A061 " "J219" "A062 " "S024" "A063 " "N390" "A064 " "Q039" "A065 " "G473" "A066 " end
I want Stata to remember the string values of var2 and check if there is any occasion where there is a match in var1 then create a dummy variable and assign value of 1 to it. I tried the following:
Code:
levelsof var2 , local (codes) gen Flag =0 foreach n of local codes { replace Flag =1 if ( var1 == "`n'") }
Is there anyway around to achieve it? I also tried egen any match but it says in the error msg that var1 is a string variable and cannot be included in the varlist!
Comment