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
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!
0 Response to Count number of time where at least x number of consecutive rows have the same value
Post a Comment