I have a list of people, registration times, and scores. In Stata I want to calculate a moving average of score based on a time window around each observation (not a window based on lagging/leading number of observations).
For example, assuming +/- 2 days on either side and not including the current observation, I'm trying to calculate something like this:
user_id day score window_avg
A 1 1 1.5 = (avg of B and C)
B 1 2 1 = (avg of A and C)
C 3 1 2.25 = (avg of A, B, D, and E)
D 4 3 2 = (avg of C and E)
E 5 3 2.5 = (avg of C, D, F, and G
F 7 1 4 = (avg of E and G)
G 7 5 2 = (avg of E and F)
H 10 3 . = blank
I've attempted to define the dataset with tsset
and then use tssmooth
, but couldn't get it to work. Since there may be multiple observations for a given time period I'm not sure this is even the right approach. Also, in reality the day variable is a tc
timestamp.