I want to calculate the cumulative count within id. Below is an example where x is a dummy and I count the =1 within id over t.
The complication is that I want to allow only for short breaks in spell length. So if the spell break with x=0 is shorter or equal than 3 periods, than I continue counting, otherwise I reset to zero.
Below in the example, I have added the outcome y (I only care about the variable if x=1. Not important how it defined for the obs with x=0).
MWE
The complication is that I want to allow only for short breaks in spell length. So if the spell break with x=0 is shorter or equal than 3 periods, than I continue counting, otherwise I reset to zero.
Below in the example, I have added the outcome y (I only care about the variable if x=1. Not important how it defined for the obs with x=0).
MWE
Code:
clear input id t x y 1 2 1 1 1 2 0 1 1 2 1 2 1 2 0 2 1 2 0 2 1 2 0 2 1 2 0 0 1 2 1 1 end
Comment