I am trying to code if a listing existed in a certain month between the start date of the listing and the last date of the listing.
Listing timestamp_first timestamp_last M1 M2 M3 M4 M5
0001 1 5 1 1 1 1 1
0002 2 5 0 1 1 1 1
0003 3 5 0 0 1 1 1
Coding the above was rather simple for me by using the following syntax:
gen M1 = (timestamp_first<2)
gen M2 = (timestamp_first<3)
gen M3 = (timestamp_first<4)
etc.....

However this code does not work when for some listing (e.g. 0004) the last timestamp is not 5 as in the above example, but 3. See below table:
Listing timestamp_first timestamp_last M1 M2 M3 M4 M5
0004 2 3 0 1 1 0 0
Does anyone of you have a nice syntax to get the above result (M1=0, M2=1, M3=1, M4=0, M5=0)?

Thank you very much in advance.