I think there is a much easier way of doing this. You don't need to create a file with migrants as your unit of analysis. See the below code:
use "NPHR60FL.dta"
* Rename variable to drop 0 to allow forvalues below to work
rename sh27_0* sh27_*
rename sh28c_0* sh28c_*
* Initialize to code 2
gen var1=2
* Loop through all migrants and set to var1 if any meet the condition.
forvalues x = 1/16 {
replace var1=1 if sh21==1 & sh27_`x'==1 & sh28c_`x'>=2
}
* rename variables for matching
rename hv001 v001
rename hv002 v002
keep v001 v002 var1
sort v001 v002
save "var1.dta"
* open IR file and merge
use "NPIR60FL.dta", clear
merge m:1 v001 v002 using "var1.dta"