I have a data set (shown below). I want to generate a new variable that counts the number of times v1, v2, and v3 are greater than or equal to time. This, however, does not include cases where v1, v2, or v3 are the last observation in the row. In this case, the last observation cannot equal time.
Code:
clear
input float(obs time v1 v2 v3)
1 1 1 2 3
2 2 1 . .
3 3 3 4 .
4 4 4 . .
5 . 1 2 .
6 . 1 . .
7 . 3 4 .
8 . 2 4 .
end
tempfile dataset1
save `dataset1'
Code:
clear
input float(obs time v1 v2 v3 Count)
1 1 1 2 3 6
2 2 1 . . 5
3 3 3 4 . 4
4 4 4 . . 0
5 . 1 2 . .
6 . 1 . . .
7 . 3 4 . .
8 . 2 4 . .
end
tempfile dataset1
save `dataset1'
Thanks,
A
0 Response to Generating new variable by counting observations
Post a Comment