I have a dataset of analyst forecasts. I am wanting to produce a rolling average for each firm. Normally, this would be simple and I could accomplish using EXPAND or using an accumulator variable and dividing by the count. However, In my case an analyst can make more than one forecast in a period. If they do, I only want one of their forecasts to go into the rolling average at a time. I am copying below an example of the data. DATE FIRMID ANALYSTID ESTIMATE Average(want) 1/1/2015 1 1 0.5 0.5 1/1/2015 1 2 0.6 0.55 1/4/2015 1 3 0.7 0.6 1/10/2015 1 2 0.8 0.666666667 1/12/2015 1 3 0.9 0.733333333 1/12/2015 1 1 1 0.9 Up until (and including) 1/4/2015 it is a normal rolling average. However, starting with 1/10/2015 previous estimates drop out of the average. Specifically, the 1/1/2015 estimate by analyst 2 should no longer be included once the 1/10/2015 estimate by analyst 2 is now included. The data I copied in is just an example. In reality, it goes across many years, firms, and analysts. I would want the average to reset for each firm-quarter. However, if I can get the logic for my example data, I believe I can extend it to the broader dataset. I appreciate any help you have to offer.
... View more