Skip to content

Commit

Permalink
Fill in using latest data first
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoch94 committed Oct 14, 2024
1 parent 8ad74bf commit 99117cf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions R/adapt_source.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,30 @@ adapt_source <- function(gdp, source, with_regions, replace_NAs, require_year_co
dplyr::group_by(.data$iso3c) %>%
tidyr::fill(c("MER (LCU per US$)",
"PPP conversion factor, GDP (LCU per international $)"),
.direction = "downup") %>%
.direction = "updown") %>%
dplyr::ungroup() %>%
# For the deflator, we need to multiply the bordering values with the actual USA growth
dplyr::left_join(USA_def_growth, by = dplyr::join_by("year")) %>%
# Forward
# Backward
dplyr::arrange(-.data$year) %>%
dplyr::mutate(
`GDP deflator` = purrr::accumulate(
dplyr::row_number(),
~ dplyr::coalesce(.data$`GDP deflator`[.y], .x * .data$gd[.y]),
~ dplyr::coalesce(.data$`GDP deflator`[.y], .x / .data$gd[.y]),
.init = NA
)[-1],
.by = c("iso3c")
) %>%
# Backward
dplyr::arrange(-.data$year) %>%
dplyr::arrange(.data$iso3c, .data$year) %>%
# Forward
dplyr::mutate(
`GDP deflator` = purrr::accumulate(
dplyr::row_number(),
~ dplyr::coalesce(.data$`GDP deflator`[.y], .x / .data$gd[.y]),
~ dplyr::coalesce(.data$`GDP deflator`[.y], .x * .data$gd[.y]),
.init = NA
)[-1],
.by = c("iso3c")
) %>%
dplyr::arrange(.data$iso3c, .data$year) %>%
dplyr::select(-"gd")

# If there is no PPP data whatsoever for the country, use MERs
Expand Down

0 comments on commit 99117cf

Please sign in to comment.