Hi everyone!
I have panel data: For each game_id (e.g. 10), I have daily prices over a period. The length of the period varies strongly: 5 years to about 6 month.
I am trying to calculate a moving average for the daily prices for each game_id (e.g. 10).
I tried the following:
This works fine, but obviously uses the same rolling interval (window size) for all game_ids.
However, for game_ids where I have smaller observed periods (meaning less days), a window size of [-180,180] is too large.
Is there any way to make the interval boundaries dependent on the length of the period (number of days of that game_id), so that games with a smaller period length have a smaller window sizes?
Maybe a loop that iterates through each group (game_id), first checks the number of days present and then uses the number of days to adapt the interval for that game_id?
Here are some exemplary rows:
I am also open for other approaches if range stat is not the way to go here - although it takes care of a lot of cases that would be a pain to solve manually.
Thank you very much in advance!
I have panel data: For each game_id (e.g. 10), I have daily prices over a period. The length of the period varies strongly: 5 years to about 6 month.
I am trying to calculate a moving average for the daily prices for each game_id (e.g. 10).
I tried the following:
Code:
rangestat (mean) price, interval(date -180 180) by(game_id)
However, for game_ids where I have smaller observed periods (meaning less days), a window size of [-180,180] is too large.
Is there any way to make the interval boundaries dependent on the length of the period (number of days of that game_id), so that games with a smaller period length have a smaller window sizes?
Maybe a loop that iterates through each group (game_id), first checks the number of days present and then uses the number of days to adapt the interval for that game_id?
Here are some exemplary rows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long game_id float(date price) 10 20054 3.74 10 20055 4.99 10 20056 4.99 10 20057 4.99 10 20058 4.99 10 20059 9.99 10 20060 9.99 10 20061 9.99 10 20062 9.99 10 20063 9.99 10 20064 9.99 10 20065 9.99 10 20066 9.99 10 20067 9.99 10 20068 9.99 10 20069 9.99 10 20070 9.99 10 20071 9.99 10 20072 9.99 10 20073 9.99 ... 22 20054 2.20 22 20055 5.30 22 20056 5.30 22 20057 6.20 22 20058 6.20 22 20059 2.20 22 20060 1.30 end format %td date
I am also open for other approaches if range stat is not the way to go here - although it takes care of a lot of cases that would be a pain to solve manually.
Thank you very much in advance!
Comment