Hi everyone, I have this dataset that contains information on the relationship of each household member to the respondent. I have this dataset for multiple waves of the data. In each wave, there are about 15 or so variables indicating the relationship between each household member and the respondent. The variables take on variety of codes (e.g, 1, 2 , 17, 20, 45 etc.) depending on who the household member is (e.g., mother, father, sister, grandmother, friend, stepfather, etc.). The dataset basically looks like this:

Code:
clear 
input id var1 var2 var3 var4 var5
123 3 6 9 12 13 
456 1 2 3 6 7
789 12 16 17 13 14
135 12 19 6 11 13
579 19 21 24 2 1
258 17 19 9 22 2 7 

end
I would like to create a variable that equals 1 when any of the variables (vars1-vars5) take on values between 3-6 (inclusive) or 22. The variable should equal zero when none of the variables take on the values between 3-6 or 22. In other words, I would like my data to look like this:

Code:
clear 
input id var1 var2 var3 var4 var5 var6
123 3 6 9 12 13 1
456 1 2 3 6 7 1
789 12 16 17 13 14 0
135 12 19 6 11 13 1
579 19 21 24 2 1 0
258 17 19 9 22 2 7 1


end
Typically, I could just write

Code:
gen var6 = .
replace var6 = 1 if (inrange(var1,3,6) | var1 == 22)
replace var6 = 1 if (inrange(var2,3,6) | var1 == 22)
replace var6 = 1 if (inrange(var3,3,6) | var1 == 22)
.
.
.
replace var6 = 0 if !((inrange(var5,3,6) | var1 == 22)
replace var6 = 0 if !((inrange(var5,3,6) | var1 == 22)
replace var6 = 0 if !((inrange(var5,3,6) | var1 == 22)
However, this seems inefficient and cumbersome. It's even more so when I have 15+ variables for 18 waves of data.

I've tried looking around Statalist and haven't yet found a similar question, so I was hoping someone could give me some guidance on most efficient way to generate this variable.

Please let me know if anything I said is unclear or if I should provide more info.