I want to generate a variable which sums up the number of events for a specific company in the past 10 years. I don't want to include in this count the current event date (i.e. if there is no prior event for a specific company/date, it will be assigned a value of 0 for that company/date)
What I have is "company id" (Column 1) and "event date" (Column 2) and I want to generate is "# events in the last 10 years" Column 3 as below:
What I have is "company id" (Column 1) and "event date" (Column 2) and I want to generate is "# events in the last 10 years" Column 3 as below:
company id | event date | # events in the last 10 years |
Y8547N | 15Jan07 | 0 |
Y8547N | 13Apr07 | 1 |
Y8547N | 29May07 | 2 |
Y8547N | 15Jun07 | 3 |
Y8547N | 03Aug07 | 4 |
Y8547N | 03Sep09 | 5 |
Y8547N | 09Nov09 | 6 |
Y8547N | 23Mar11 | 7 |
Y8547N | 15Jun12 | 8 |
Y8547N | 15Jun12 | 8 |
Y8547N | 11Apr13 | 10 |
Y8547N | 29Jul13 | 11 |
Y8547N | 19May15 | 12 |
Y8547N | 23Dec16 | 13 |
Y8547N | 25Jan17 | 13 |
Y85484 | 27Mar12 | 0 |
Y85484 | 12Nov13 | 1 |
Y8548U | 15Jan07 | 0 |
Y8548U | 26Jan07 | 1 |
Y8548U | 27Mar07 | 2 |
Y8548U | 27Mar07 | 2 |
Y8548U | 14Dec07 | 4 |
Comment