I would like to create a dummy variable if any variables in two different groups (uspc* and us_class*) match.
For instance, I would like to have a dummy var = 1 if uspc2 = us_class9 (i.e. dummy = 1 if uspc* = us_class*).
My dataset looks like as follows:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float newid long naics6 double year int(uspc1 uspc2 uspc3 uspc4) float uni_id long patent_id str4(us_class1 us_class2 us_class3 us_class4 us_class5) . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 673 3945202 "149" "60" "" "" "" . . . . . . . 577 3947247 "516" "8" "" "" "" . . . . . . . 577 3947247 "516" "8" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" 7197 333241 2009 . . . . 527 3948213 "118" "" "" "" "" end
I have tried some codes like:
foreach v of varlist uspc* {
foreach x of valist us_class* {
gen same_sector = 0
replace same_sector = 1 if `x' = `v'
}
}
But as you all might guess, it does not work.
I have searched some relevant FAQ but I have not yet found the solution..
Could someone help me with this issue?
Thanks !
0 Response to create a dummy variable if variables in two groups match
Post a Comment