Hello everyone,
I am wondering if anyone could help to create a command that automates counting the number of observations based on date. Basically, I would like the NewVar to be created based on the Cusip and Date, but the NewVar will be created by the number of same cusip up until a particular day and month of the same year, not past a day and month of the same year. Below, I have an example of how it should look like:
As you see, for ID#2 row, the NewVar is a total of 1 (the date before its own date), while ID#3 accounts for obs of 2 in the NewVar (the two dates before its own date).
I am wondering if anyone could help to create a command that automates counting the number of observations based on date. Basically, I would like the NewVar to be created based on the Cusip and Date, but the NewVar will be created by the number of same cusip up until a particular day and month of the same year, not past a day and month of the same year. Below, I have an example of how it should look like:
ID | Cusip | Date | NewVar |
1 | 100110 | 01jan2014 | 0 |
2 | 100110 | 04apr2014 | 1 |
3 | 100110 | 02may2014 | 2 |
4 | 201212 | 21mar2015 | 0 |
5 | 201212 | 03may2015 | 1 |
6 | 201212 | 20aug2015 | 2 |
7 | 201212 | 20aug2015 | 2 |
Comment