Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 2017 GDP Base Year #122

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '28699896'
ValidationKey: '28784160'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrcommons: MadRat commons Input Data Library'
version: 1.43.6
date-released: '2024-09-20'
version: 1.44.0
date-released: '2024-09-23'
abstract: Provides useful functions and a common structure to all the input data required
to run models like MAgPIE and REMIND of model input data.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mrcommons
Type: Package
Title: MadRat commons Input Data Library
Version: 1.43.6
Date: 2024-09-20
Version: 1.44.0
Date: 2024-09-23
Authors@R: c(person("Benjamin Leon", "Bodirsky", email = "bodirsky@pik-potsdam.de", role = "aut"),
person("Kristine", "Karstens", role = "aut"),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
4 changes: 2 additions & 2 deletions R/calcGTAPTotalTransportCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ calcGTAPTotalTransportCosts <- function(costType = "transport", version = "9") {
totalTcosts <- (tcostInputs + tcostToSecondary) / 2

totalTcosts <- GDPuc::convertGDP(totalTcosts, unit_in = "current US$MER",
unit_out = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")

return(list(x = totalTcosts,
weight = NULL,
unit = "million constant 2005 US$MER/yr",
unit = "million constant 2017 US$MER/yr",
description = "Costs for GTAP commodities (half of input to market and market to value"))
}
27 changes: 24 additions & 3 deletions R/calcIniFoodPrice.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param year Specifies the year for the initialization of prices in MAgPIE. Default is `y2005`.
#' @param products subselection of products to be returned
#'
#' @return List with a magpie object with commodity prices on global level in $05/tDM.
#' @return List with a magpie object with commodity prices on global level in $17/tDM.
#' @author Mishko Stevanovic, Benjamin Leon Bodirsky
#' @seealso
#' [readIMPACT3.2.2World_Price()]
Expand All @@ -27,7 +27,7 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
dm <- collapseNames(dm)

if (datasource == "IMPACT3.2.2World_Price") {
out <- readSource("IMPACT3.2.2World_Price")
out <- readSource("IMPACT3.2.2World_Price") # in 2017 prices now
# select scenario and initial year
out <- collapseNames(out[, year, "SSP2-NoCC-NoCC-379"])
out <- setYears(out, NULL)
Expand Down Expand Up @@ -69,6 +69,17 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
out[, , "pasture"] <- 50 # quick google search
out[, , "scp"] <- 1500 # using upper end prices similar to fishmeal

# [DC] At some point probably better to do another 'quick google search',
# for now convert these to 2017 values using US inflation, also for consistency
conv <- c("sugr_cane", "sugr_beet", "alcohol", "fish", "oilpalm", "oilcakes", "cottn_pro", "foddr",
"brans", "distillers_grain", "ethanol", "fibres", "molasses", "wood", "woodfuel", "begr",
"betr", "res_cereals", "res_fibrous", "pasture", "scp")
getItems(out, dim = 1) <- "USA"
out[, , conv] <- GDPuc::convertGDP(out[, , conv], unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(out, dim = 1) <- "GLO"

# correct the prices for dry matter values
out <- out[, , ] / dm[, , ]

Expand Down Expand Up @@ -106,6 +117,16 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
out[, , "foddr"] <- 50 # quick google search
out[, , "sugar"] <- 250 # quick google search

conv <- c("fish", "oilcakes", "brans", "distillers_grain", "ethanol", "alcohol",
"molasses", "wood", "woodfuel", "begr",
"betr", "res_cereals", "res_fibrous", "pasture", "scp",
"foddr", "sugar")
getItems(out, dim = 1) <- "USA"
out[, , conv] <- GDPuc::convertGDP(out[, , conv], unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(out, dim = 1) <- "GLO"

# correct the prices from online sources for dry matter values
out[, , missingCommodities] <- out[, , missingCommodities] / dm[, , missingCommodities]

Expand All @@ -120,7 +141,7 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo

return(list(x = out,
weight = NULL,
unit = "US$05/tDM",
unit = "US$2017/tDM",
description = description,
isocountries = FALSE))
}
47 changes: 11 additions & 36 deletions R/calcMAgPIEReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,15 @@ calcMAgPIEReport <- function(subtype) {
x <- readSource("MAgPIE", subtype = "MAgPIEReport_extensive")

if (subtype == "CostTotal") {
# with transformation factor from 10E6 US$2005 to 10E12 US$2005
x <- x[, , "Costs Without Incentives (million US$05/yr)"] / 1000 / 1000

# convert from US$2005 -> US$2017
x <- GDPuc::convertGDP(
gdp = x,
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

getNames(x) <- gsub("US\\$05", "US\\$17", getNames(x))

# with transformation factor from 10E6 US$2017 to 10E12 US$2017
x <- x[, , "Costs Without Incentives (million US$17/yr)"] / 1000 / 1000
d <- "Total Landuse Costs from MAgPIE excluding emission costs"
u <- "trillion US$2017/yr"

u <- "T$2017/yr"
} else if (subtype == "CostMAC") {

# with transformation factor from 10E6 US$2005 to 10E12 US$2005
x <- x[, , "Costs Accounting|+|MACCS (million US$05/yr)"] / 1000 / 1000

# convert from US$2005 -> US$2017
x <- GDPuc::convertGDP(
gdp = x,
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

getNames(x) <- gsub("US\\$05", "US\\$17", getNames(x))

# with transformation factor from 10E6 US$2017 to 10E12 US$2017
x <- x[, , "Costs Accounting|+|MACCS (million US$17/yr)"] / 1000 / 1000
d <- "MAC Costs for LU emissions from MAgPIE"
u <- "trillion US$2017/yr"

u <- "T$2017/yr"
} else if (subtype == "ProductionBiomass") {
x <- x[, , "Demand|Bioenergy|2nd generation|++|Bioenergy crops (EJ/yr)"] / 31.536 # EJ to TWa
d <- "Production of ligno-cellulosic purpose grown biomass in MAgPIE"
Expand Down Expand Up @@ -90,11 +65,11 @@ calcMAgPIEReport <- function(subtype) {
getNames(x) <- getNames(x) %>%
stringr::str_replace_all(c(
"^C_" = "",
#"-PkBudg900-mag-4" = ".rcp20", # in 2022-10 still in emulator files
#"-PkBudg500-mag-4" = ".rcp20", # in 2023-10 still in emulator files
# "-PkBudg900-mag-4" = ".rcp20", # in 2022-10 still in emulator files
# "-PkBudg500-mag-4" = ".rcp20", # in 2023-10 still in emulator files
"-PkBudg650-mag-4" = ".rcp20",
#"-PkBudg1300-mag-4" = ".rcp26", # in 2022-10 still in emulator files
#"-PkBudg1150-mag-4" = ".rcp26", # in 2023-10 still in emulator files
# "-PkBudg1300-mag-4" = ".rcp26", # in 2022-10 still in emulator files
# "-PkBudg1150-mag-4" = ".rcp26", # in 2023-10 still in emulator files
"-PkBudg1050-mag-4" = ".rcp26",
"-NDC-mag-4" = ".rcp45",
"-Base-mag-4" = ".none",
Expand All @@ -103,7 +78,7 @@ calcMAgPIEReport <- function(subtype) {
))

# add values for SSP3 copying the values from SSP2
tmp <- x[,,"SSP2"]
tmp <- x[, , "SSP2"]
getNames(tmp) <- gsub("SSP2", "SSP3", getNames(tmp))
x <- mbind(x, tmp)

Expand Down
10 changes: 5 additions & 5 deletions R/calcPriceAgriculture.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' @importFrom reshape2 melt acast
#'

calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "US$05/tDM") {
calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "US$17/tDM") {

if (datasource == "IMPACT3.2.2World_Price") {

Expand Down Expand Up @@ -70,7 +70,7 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "

} else if (datasource == "WBGEM") {

# Prices in US$05/tDM
# Prices in US$17/tDM
x <- calcOutput("WBGEM", aggregate = FALSE)

# sectoral mappings
Expand Down Expand Up @@ -138,7 +138,7 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "

} else if (datasource == "FAO") {

# Annual producer prices in US$05/tDM
# Annual producer prices in US$17/tDM
out <- readSource("FAO_online", subtype = "PricesProducerAnnual", convert = TRUE)
aggregation <- toolGetMapping("FAOitems_online.csv",
type = "sectoral", where = "mappingfolder")
Expand Down Expand Up @@ -184,10 +184,10 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "
isocountries <- TRUE
}

if (unit != "US$05/tDM") {
if (unit != "US$17/tDM") {
# Transform to selected currency unit
out <- GDPuc::convertGDP(out,
unit_in = "constant 2005 US$MER",
unit_in = "constant 2017 US$MER",
unit_out = unit,
replace_NAs = "no_conversion")
}
Expand Down
11 changes: 9 additions & 2 deletions R/calcWBGEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ calcWBGEM <- function() {
setNames(x[, , grep("nominal", sugar, value = TRUE)], NULL), NULL)
adjustFactor2005 <- 1 / setYears(x[, 2005, grep("real", sugar, value = TRUE)] /
setNames(x[, 2005, grep("nominal", sugar, value = TRUE)], NULL), NULL) *
adjustFactor2010
adjustFactor2010
adjustFactor2005 <- setNames(adjustFactor2005, NULL)

vars <- grep("nominal", getNames(x), value = TRUE)
Expand All @@ -45,8 +45,15 @@ calcWBGEM <- function() {
out <- out * adjustFactor2005
out[is.na(out)] <- 0

# inflate to 2017 using US inflation for global value
getItems(out, dim = 1) <- "USA"
out <- GDPuc::convertGDP(out, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(out, dim = 1) <- "GLO"

return(list(x = out,
unit = "real2005 USD per ton",
unit = "real2017 USD per ton",
weight = NULL,
description = "WBGEM global price of commodity"))
}
4 changes: 1 addition & 3 deletions R/convertGTAPv8v9.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ convertGTAPv8v9 <- function(x, subtype) {

} else {
gdpMer <- calcOutput("GDPPast", GDPPast = "WDI-MI",
unit = "constant 2005 US$MER", aggregate = FALSE)
unit = "constant 2017 US$MER", aggregate = FALSE)
gdpMer <- gdpMer[, getYears(x), , drop = TRUE]


w1 <- GDPuc::convertGDP(gdpMer,
unit_in = "constant 2017 US$MER",
unit_out = "current US$MER",
Expand Down
24 changes: 14 additions & 10 deletions R/convertICP2017.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title convertICP2017
#' @description converts data of World Bank ICP round, downloaded from
#' here: https://databank.worldbank.org/source/icp-2017
#' mainly a currency conversion to MER05. Assume that in the original dataset,
#' mainly a currency conversion to MER2017. Assume that in the original dataset,
#' 2011 values are in 2011MER and 2017 in 2017MER, given the ICP rounds
#'
#' @param subtype data subtype needed. Either "priceLevel", or "per_cap_exp"
Expand All @@ -17,29 +17,33 @@ convertICP2017 <- function(x, subtype = "per_cap_expMER") {
# currency convert for expenditures
if (subtype == "per_cap_expMER") {

x2011 <- GDPuc::convertGDP(x[, 2011, ], unit_in = "constant 2011 US$MER", unit_out = "constant 2005 US$MER")
x2017 <- GDPuc::convertGDP(x[, 2017, ], unit_in = "constant 2017 US$MER", unit_out = "constant 2005 US$MER")
x2011 <- GDPuc::convertGDP(x[, 2011, ],
unit_in = "constant 2011 US$MER",
unit_out = "constant 2017 US$MER")
x2017 <- x[, 2017, ]
x <- mbind(x2011, x2017)
x[is.na(x)] <- 0
}

# currency convert for expenditures
if (subtype == "per_cap_expPPP") {

x2011 <- GDPuc::convertGDP(x[, 2011, ], unit_in = "constant 2011 US$PPP", unit_out = "constant 2005 US$MER")
x2017 <- GDPuc::convertGDP(x[, 2017, ], unit_in = "constant 2017 US$PPP", unit_out = "constant 2005 US$MER")
x2011 <- GDPuc::convertGDP(x[, 2011, ],
unit_in = "constant 2011 US$PPP",
unit_out = "constant 2017 US$MER")
x2017 <- x[, 2017, ]
x <- mbind(x2011, x2017)
x[is.na(x)] <- 0
}

# remove aggregate categories

x <- x[, , c("GROSS DOMESTIC PRODUCT",
"FOOD AND NON-ALCOHOLIC BEVERAGES",
"ALCOHOLIC BEVERAGES, TOBACCO AND NARCOTICS",
"HOUSEHOLDS AND NPISHS FINAL CONSUMPTION EXPENDITURE",
"INDIVIDUAL CONSUMPTION EXPENDITURE BY HOUSEHOLDS WITHOUT HOUSING",
"GENERAL GOVERNMENT FINAL CONSUMPTION EXPENDITURE"), invert = TRUE]
"FOOD AND NON-ALCOHOLIC BEVERAGES",
"ALCOHOLIC BEVERAGES, TOBACCO AND NARCOTICS",
"HOUSEHOLDS AND NPISHS FINAL CONSUMPTION EXPENDITURE",
"INDIVIDUAL CONSUMPTION EXPENDITURE BY HOUSEHOLDS WITHOUT HOUSING",
"GENERAL GOVERNMENT FINAL CONSUMPTION EXPENDITURE"), invert = TRUE]


return(x)
Expand Down
Loading