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 9c2fb2b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2821410'
ValidationKey: '2621310'
AutocreateReadme: no
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'GDPuc: Easily Convert GDP Data'
version: 1.4.1
version: 1.3.1
date-released: '2024-10-14'
abstract: Convert GDP time series data from one unit to another. All common GDP units
are included, i.e. current and constant local currency units, US$ via market exchange
Expand Down
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 9c2fb2b

Please sign in to comment.