Good day,

I have a general question regarding best practices for panel data which is non-missing for some variables and missing on Saturdays/Sundays/holidays for other variables. To give an example, here's some data I made up. Return is the stock market return for country A on a given day. Google is the number of Google searches about a particular topic for country A on a given day. There are other countries in the made-up sample that aren't shown here. I'm interested in asking Stata to create a variable "Average5" that is the average of the returns over the last 5 days on which the market was open in the given country (non-missing). I have to be careful because some countries have a holiday on a given day while others do not. Therefore, I can't simply say "give me the average over the last 7 calendar days", because the last 7 calendar days will not necessarily have 5 non-missing observations, and the number of non-missing observations may be different across countries depending on holiday differences. What is the best way to ask Stata to give me the average of the last 5 non-missing returns day-by-day, country-by-country?

Thank you, and happy Memorial Day for those in a country that has a holiday!
Stan
Day DofW Country Return Google
1 Monday A 0.248993 76
2 Tuesday A 0.635337 45
3 Wednesday A 0.511604 78
4 Thursday A 0.668078 34
5 Friday A 0.85938 94
6 Saturday A . 48
7 Sunday A . 63
8 Monday A 0.550717 71
9 Tuesday A 0.62901 92
10 Wednesday A 0.930895 76
11 Thursday A 0.081141 45
12 Friday A 0.992014 78
13 Saturday A . 34
14 Sunday A . 94
15 Monday A 0.375389 48
16 Tuesday A 0.304097 63
17 Wednesday A 0.428649 71
18 Thursday A 0.623587 92
19 Friday A 0.611869 55
20 Saturday A . 51
21 Sunday A . 60