Hi all
I've searched on the forum and found some things that are helpful but can't seem to adapt them to my needs.
I have three string variables var1 var2 var3 and I would like to assign group1=caseid to any cases that have values that appear in var1 and var2. group2=caseid to any cases that have values that appear in both var1 and var3 and group3=caseid to any cases that have values that appear in both var2 and var3.
Then I would like to assign group4=caseid to any cases that have values that appear in all var1, var2 and var3.
I think the loop function would be useful but I've tried this and I think I'm on the wrong track as it assigns caseid to all cases
gen group1 = .
forvalues caseid=1/34387 {
foreach var of varlist var1-var2 {
replace group1 = caseid if var1==var2
}
}
many thanks in advance
I've searched on the forum and found some things that are helpful but can't seem to adapt them to my needs.
I have three string variables var1 var2 var3 and I would like to assign group1=caseid to any cases that have values that appear in var1 and var2. group2=caseid to any cases that have values that appear in both var1 and var3 and group3=caseid to any cases that have values that appear in both var2 and var3.
Then I would like to assign group4=caseid to any cases that have values that appear in all var1, var2 and var3.
I think the loop function would be useful but I've tried this and I think I'm on the wrong track as it assigns caseid to all cases
gen group1 = .
forvalues caseid=1/34387 {
foreach var of varlist var1-var2 {
replace group1 = caseid if var1==var2
}
}
many thanks in advance
Comment