-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.5 prepare_weo_inflation.R
48 lines (35 loc) · 1.76 KB
/
1.5 prepare_weo_inflation.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#### Script to prepare inflation forecast from WEO
# Set paramters: -----
sheets <- getSheetNames("../Forecasts_Time_Covid_material/raw_data/WEO/inflation.xlsx") %>%
str_subset(.,"2020")
var_name=c("Apr","Jan","Jun","Oct")
# Clean inflation sheet with 2020 estimates: -----
weo_inflation <- sheets %>%
map(~ read_xlsx("../Forecasts_Time_Covid_material/raw_data/WEO/inflation.xlsx", sheet = .x)) %>%
set_names(sheets) %>%
map(~ .x %>% slice(1: which(Country == "Zimbabwe"))) %>%
map(~ .x %>% select(Series_code, `2019`:`2020`)) %>%
map(~ .x %>% select(-matches("Q"))) %>%
map(~ .x %>% mutate(country_code = str_extract(Series_code,"\\d{3}"))) %>%
map(~ .x %>% mutate(growth_2020 = ((`2020` - `2019`)/`2019`)*100,
year = "2020")) %>%
map(~ .x %>% select(country_code,year,growth_2020)) %>%
map2(var_name, ~ .x %>% setNames(c("country_code", "year", .y))) %>%
map(~ .x %>% gather("horizon","value",3)) %>%
reduce(rbind)
# Clean actuals sheet: -----
actuals <- read_xlsx("../Forecasts_Time_Covid_material/raw_data/WEO/inflation.xlsx", sheet = "apr2021") %>%
slice(1: which(Country == "Zimbabwe")) %>%
select(Series_code, `2019`:`2020`) %>%
select(-matches("Q")) %>%
mutate(country_code = str_extract(Series_code,"\\d{3}")) %>%
mutate(Actual = ((`2020` - `2019`)/`2019`)*100,
year = "2020") %>%
select(country_code,year,Actual)
# Merge and export:
merge(weo_inflation, actuals, by=c("country_code","year")) %>%
mutate(country = countrycode(country_code,"imf","country.name")) %>%
filter(complete.cases(country)) %>%
select(country, country_code, year, horizon, Actual, value) %>%
as_tibble() %>%
saveRDS("../Forecasts_Time_Covid_material/intermediate_data/weo_2020_inflation.RDS")