Hi, Thanks for your reply. Yes, you assumed correctly, I meant 60 days by 60. The suggested code does not work unfortunately, because it only takes into account the previous observation with the lag function. The code gives a value of 4 of LINE variable in the row 13, when it should be 5 because when comparing the date_start + 60 the reference should be the first date_start of the LINE variable. Do you have an other suggestion maybe? Row id atc date_start date_stop Line 1 1 A 2010-07-02 2011-08-17 1 2 1 B 2011-08-17 2011-09-09 2 3 1 C 2011-09-09 2011-11-10 2 4 1 D 2011-11-14 2012-02-08 3 5 2 E 2007-03-17 2009-07-01 1 6 2 F 2007-06-29 2009-11-12 2 7 2 A 2007-07-17 2010-06-22 2 8 2 B 2007-08-14 2010-11-04 2 9 2 A 2007-09-04 2011-02-17 3 10 2 D 2008-02-18 2011-06-20 4 11 2 F 2008-03-21 2011-08-19 4 12 2 A 2008-04-15 2011-09-28 4 13 2 B 2008-04-29 2011-10-18 5 14 2 K 2008-05-15 2011-12-01 5 Thanks, Gib
... View more