Dear All, I found this question here (https://bbs.pinggu.org/thread-7891870-1-1.html). The data set is
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(id event n)
200003 0 1
200003 0 2
200003 1 3
200003 1 4
200003 0 5
200003 0 6
200003 1 7
200003 1 8
200007 1 1
200007 1 2
200007 0 3
200007 0 4
200007 1 5
200007 1 6
200007 1 7
end
For each `id', the data set is in a sequence denoted by `n'. I'd like to identify a sequence with pattern 1,1,(0,0,0),1,1. I.e., starting with two `1's (first pair) and ending with two `1's (second pair). Among which, there can be different numbers of `0'. For example, for id=200003, the observations between n=3 to n=8 satisfy this requirement. I want to know which `n' (in this case, n=7 is my desired answer, probably denoted by a new variable `wanted') corresponding to the first `1' in the second pair of `1's. Any suggestions? Thanks.