Hi

I have data "sort and tsset" by quarter_date week. The time-series data include quarter_date, week of the quarter (from 1 to 12), and an indicator variable labeled as meeting (equal to 1 when there is a meeting during a certain week of the quarter and zero otherwise).


I want to create another indicator variable that is equal to 1 when the next week or the week after has a meeting equal to 1 (even if the next weeks are in the next quarter). I did the following:

gen pre_meeting=0
replace pre_meeting=1 if f.meeting==1 | f2.meeting==1

As you may see now, the problem is that, according to my code above, week 12 will never have a value of 1 for the pre_meeting value. Also, Week 11's pre-meeting will only have a value of 1 if week 12's meeting is 1 but not when week 1's meeting in the next quarter is equal to 1.

How can I adjust my code to be able to apply the same conditions to all weeks including weeks 11 and 12? i.e, If week 1 or 2 of a quarter has a value of 1 for meeting then pre-meeting of week 12 in the previous quarter should be 1. Also, if week 1 of a quarter or week 12 of a previous quarter are equal to 1 then week 11 of the same quarter as of week 12 should have pre-meeting equal to 1

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(quarter_date week meeting)
48  1 0
48  2 1
48  3 0
48  4 0
48  5 0
48  6 1
48  7 1
48  8 0
48  9 0
48 10 0
48 11 1
48 12 0
49  1 0
49  2 0
49  3 1
49  4 0
49  5 0
49  6 0
49  7 0
49  8 1
49  9 0
49 10 0
49 11 1
49 12 0
50  1 0
50  2 0
50  3 1
50  4 0
50  5 0
50  6 0
50  7 1
50  8 0
50  9 0
50 10 0
50 11 1
50 12 0
51  1 0
51  2 0
51  3 1
51  4 0
51  5 0
51  6 0
51  7 1
51  8 0
51  9 0
51 10 0
51 11 1
51 12 0
end
format %tq quarter_date

Thanks