Hello everyone,
I have datasets that are currently in the wide format. Variables for the time are in monthly frequences. I know how to convert what I need to the long format, but I also need to convert the data from monthly entries to a yearly average value. I.e., this is what the data resembles in the wide format.
Variables v have labels, i.e. v1: Jan-84, v2: Feb-84, v3: Mar-84, ..., v403: Jul-17.
I need, for each country, to calculate a running average of the values for each year and reduce the set to a yearly dataset, for example for 1984: sum(v1Country 1+...+v12Country 1)/12
Eventually, I want to transform it to the long format and merge it with other data that is already in an annual format to perform a regression. Any idea on how to do this?
I have datasets that are currently in the wide format. Variables for the time are in monthly frequences. I know how to convert what I need to the long format, but I also need to convert the data from monthly entries to a yearly average value. I.e., this is what the data resembles in the wide format.
| Country | Variable | v1 | v2 | v3 | v4 | v5 | v6 | ... | v403 |
| Country 1 | Indicator 1 | 2 | 3 | 4 | 5 | 5 | 5 | ... | 6 |
| Country 2 | Indicator 1 | 2 | 2 | 2 | 2 | 3 | 3 | ... | 4 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| Country 146 | Indicator 1 | 5 | 5 | 6 | 6 | 5 | 5 | ... | 6 |
I need, for each country, to calculate a running average of the values for each year and reduce the set to a yearly dataset, for example for 1984: sum(v1Country 1+...+v12Country 1)/12
Eventually, I want to transform it to the long format and merge it with other data that is already in an annual format to perform a regression. Any idea on how to do this?

Comment