HHID | ACTIVITY | UID | SPECIFY | T1 | T2 | T3 | T4 | T5 |
1 | SLEEP | SLEEP1 | 0 | 0 | 0 | 0 | 0 | |
1 | EAT | EAT1 | 0 | 1 | 0 | 0 | 1 | |
1 | WORK | WORK1 | 0 | 0 | 0 | 0 | 0 | |
1 | EXERCISE | EXERCISE1 | 0 | 1 | 0 | 0 | 0 | |
1 | PLAY | PLAY1 | 1 | 0 | 0 | 0 | 0 | |
1 | OTHER | OTHER1 | napping | 1 | 0 | 1 | 1 | 0 |
2 | SLEEP | SLEEP2 | 0 | 0 | 0 | 0 | 0 | |
2 | EAT | EAT2 | 1 | 0 | 0 | 0 | 0 | |
2 | WORK | WORK2 | 1 | 0 | 0 | 0 | 0 | |
2 | EXERCISE | EXERCISE2 | 1 | 1 | 1 | 0 | 1 | |
2 | PLAY | PLAY2 | 1 | 0 | 1 | 0 | 1 | |
2 | OTHER | OTHER2 | snoozing | 0 | 0 | 0 | 1 | 0 |
3 | SLEEP | SLEEP3 | 0 | 0 | 0 | 0 | 0 | |
3 | EAT | EAT3 | 0 | 0 | 1 | 1 | 0 | |
3 | WORK | WORK3 | 0 | 0 | 1 | 0 | 1 | |
3 | EXERCISE | EXERCISE3 | 1 | 1 | 0 | 0 | 0 | |
3 | PLAY | PLAY3 | 1 | 0 | 0 | 0 | 0 | |
3 | OTHER | OTHER3 | cooking | 1 | 0 | 0 | 0 | 0 |
for HHID==1 & HHID==2
foreach var T1-T5 { // NB: There are actually 60 time periods in the real db, so this needs to be a systematic iteration
replace var[OF SLEEP]=1 if var[OF OTHER]=1 // this is the vlookup-like part
and then replace var[OF OTHER]=0 // "clear" the OTHER data because its now accounted for in SLEEP
}
I could see this being a nested loop, except that the HHIDs that need to be revised will always be one-offs...
Help?
And thank you in advance.
0 Response to Complicated vlookup-like function
Post a Comment