[size=12.800000190734863px]Hello I'm working on some project and need to count number of events between any of two event dates for each firm. I have data look like this:
event date | firm cusip | number of event +/- 183 days | number of events +/-365 days | number of event +/- 548 days |
1991/2/21 | 21 | |||
1992/3/24 | 21 | |||
1994/3/7 | 361 | |||
1997/6/10 | 361 | |||
1998/9/9 | 361 | |||
2000/1/11 | 361 | |||
2009/6/15 | 361 | |||
1996/8/2 | 375 | |||
1997/1/23 | 375 | |||
1998/3/24 | 375 | |||
1999/7/21 | 375 | |||
1999/8/26 | 375 | |||
1999/11/28 | 375 | |||
2000/1/13 | 375 | |||
2000/5/8 | 375 | |||
2000/6/15 | 375 | |||
2000/6/30 | 375 | |||
2000/7/4 | 375 | |||
2000/7/6 | 375 | |||
2000/9/25 | 375 | |||
2000/10/5 | 375 | |||
2000/10/16 | 375 | |||
2001/2/19 | 375 | |||
2004/4/1 | 375 | |||
2005/6/22 | 375 | |||
2005/12/20 | 375 | |||
2007/6/14 | 375 | |||
2008/4/16 | 375 | |||
2008/8/22 | 375 | |||
2008/10/23 | 375 | |||
2009/3/31 | 375 | |||
2009/12/10 | 375 | |||
2011/6/12 | 375 | |||
2011/8/1 | 375 | |||
2012/3/6 | 375 | |||
2013/5/7 | 375 |
[size=12.800000190734863px]For column named number of event +/- , I need to count, for the same firm, number of event dates within the range of [-183,+183], [-365,+365],[-548,+548] relative to the event date on the same row. So for example, for firm with cusip=21, there are 397 days between two event date, 1991/2/21 and 1992/3/24, so in the first row, there are 0 event within the range of [-183,+183] relative to 1991/2/21, but there are 1 event within the range of [-365,+365], and 1 event within the range of [-548,+548]. In the second row, I need to count the number of event for the same firm within these three ranges relative to the date of 1992/3/24. I need to do the same for three firms. This is the first time I do this kind of counting staff and I tried several method but they do not work on all of the firms. Please help!!