I am currently working with a wide data set and am trying to count the number of certain values across different groups of 40. The data looks like this:
# S F w1 w2 w3 w4 w5
1 w1 w5 1 10 13 9 10
2 w3 w5 0 0 0 0 10
3 w2 w4 13 0 11 0 0
I am attempting to count the number of variables greater than 10 for each observation, but between different start and finish points. For example, for person 1, I need to know how many variables are exactly 10 between w1 and w5. For person 2, I need to know how many variables are greater than 10 between w3 and w5. Each person has the same number of variables to count (40) but different starting and ending points. For each individual person, I am using this:
gen employedweeks = 0
qui foreach v of var W0067000-W0106800 {
replace employedweeks = employedweeks + (`v' > 10) if birth2 == 73
}
But am unsure if there is a way to avoid doing this for each person. Thanks for any help!
# S F w1 w2 w3 w4 w5
1 w1 w5 1 10 13 9 10
2 w3 w5 0 0 0 0 10
3 w2 w4 13 0 11 0 0
I am attempting to count the number of variables greater than 10 for each observation, but between different start and finish points. For example, for person 1, I need to know how many variables are exactly 10 between w1 and w5. For person 2, I need to know how many variables are greater than 10 between w3 and w5. Each person has the same number of variables to count (40) but different starting and ending points. For each individual person, I am using this:
gen employedweeks = 0
qui foreach v of var W0067000-W0106800 {
replace employedweeks = employedweeks + (`v' > 10) if birth2 == 73
}
But am unsure if there is a way to avoid doing this for each person. Thanks for any help!
Comment