Hello,

I have a large dataset which displays a status per time point. I want to count the number of times where the status of at least 4 consecutive time points is 1. I have been trying to do this with if-loops and for-loops, something along the lines of: if status = 1, while status = 1 : count status. But besides the fact that I cannot get it to work, there must be a more efficient or simpler way to get what I need.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(time status)
 1 0
 2 0
 3 0
 4 1
 5 1
 6 1
 7 1
 8 1
 9 0
10 0
11 0
12 1
13 1
14 1
15 0
16 1
end
In the example above, the result should be 1, because only once are there at least 4 consecutive 1's. If status at time = 15 was also 1, the result would be 2.

I tried to keep the explanation as simple as possible, so I hope my problem is understood. How do I go about in getting the result I want?

Thanks so much!