I have the information shown in the first four columns in the table below and would like to add the column Calls_previous_3_days containing the sum of calls from each CustID to each Area the previous three dates.
I.e., if a custumer made a call to Support on 17Jan2015 I would like the new variable to show the sum of the number of calls that the customer made to Support during the period 14Jan2015-16Jan2015.
How do I calculate the sum in the column Calls_previous_3_days dependent on the CustID, Area and Date?
CustID Area Date Calls Calls_previous_3_days
3137 Support 05Jan2015 1 0
3137 Support 14Jan2015 4 0
3137 Support 16Jan2015 1 4
3137 Support 17Jan2015 1 5
3137 Support 20Jan2015 2 1
3137 Support 22Jan2015 1 2
5225 Support 26Jan2015 1 0
5225 Support 27Jan2015 1 1
5225 Support 28Jan2015 1 2
5225 Sales 14Feb2015 1 0
5225 Sales 15Feb2015 1 1
5225 Sales 22Feb2015 1 0
lag
function - that should be a good starting point. Link – user667489