I have a dataset with one row per week for 2 years (so 104 rows). I have a flag column which is either 1 or 0 for each week. I want to create a new column with the following logic:
if the flag=1 for that week then have a 1 for that week and the following 3 weeks as flag_new.
My current approach, which works, is:
if flag=1 or lag(flag)=1 or lag2(flag)=1 or lag3(flag)=1 then flag_new=1;
Although this works, it becomes very tedious if I want flag_new to be 1 for the following 20 or 30 weeks instead of just 3 weeks.
I was hoping there would be an easier way to do this (perhaps a loop?), but I am not too familiar with it.
Any help is much appreciated.