For the following Panel data (Tracking the Value for unit "ID" over "Time" :
ID=c(1,1,1,1,1,2,2,2,2,2)
Time=c(1,2,3,4,5,1,2,3,4,5)
Value=c(1,9,4,8,5,2,5,9,7,6)
I would like to create a vector which is a maximum value for each "ID" over the last two days (assuming that the unit of Time is a day)
Output vector "Max_Value" would be as follows:
Max_Value=c(1,9,9,8,8,2,5,9,9,7)
To clarify, here's how Max_Value is computed for ID "1".
For ID "1", the maximum value by the "Time=1" is 1, which is a maximum of {1}.
Similarly, for ID "1", the maximum value at the "Time 2" is 9, which is a maximum of {1,9}.
Again, for ID "1", the maximum value at the "Time 3" is 9, which is a maximum of {9,4}.
For ID "1", the maximum value at the "Time 4" is 8, which is a maximum of {4,8}.
For ID "1", the maximum value at the "Time 5" is 8, which is a maximum of {8,5}.