Skip to content

Commit

Permalink
added option to use older versions of ILO data
Browse files Browse the repository at this point in the history
  • Loading branch information
Debbora Leip committed Feb 15, 2024
1 parent abfaf96 commit f5c2e5b
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '50561428'
ValidationKey: '50586312'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: 'mrvalidation: madrat data preparation for validation purposes'
version: 2.55.8
date-released: '2024-02-13'
version: 2.55.9
date-released: '2024-02-15'
abstract: Package contains routines to prepare data for validation exercises.
authors:
- family-names: Bodirsky
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrvalidation
Title: madrat data preparation for validation purposes
Version: 2.55.8
Date: 2024-02-13
Version: 2.55.9
Date: 2024-02-15
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
11 changes: 8 additions & 3 deletions R/calcValidAgEmployment.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param datasource ILO for reporting aggregated employment in crop+livestock production, or ILO_FAO, which uses the
#' same aggregated employment data from ILO, but applies FAO value of production shares to disaggregated between
#' employment in crop and in livestock production.
#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version
#'
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
Expand All @@ -15,14 +16,14 @@
#' }
#'

calcValidAgEmployment <- function(datasource = "ILO") {
calcValidAgEmployment <- function(datasource = "ILO", dataVersionILO = "Aug23") {

if (datasource == "ILO") {
agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE)[, , c("Livestock", "Crops")]
agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE)[, , c("Livestock", "Crops")]
out <- setNames(dimSums(agEmpl, dim = 3), "Labor|Employment|Agricultural employment (mio people)")
description <- "Employment in agriculture (livestock+crop production) from ILO modelled estimates"
} else if (datasource == "ILO_FAO") {
agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE)[, , c("Livestock", "Crops")]
agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE)[, , c("Livestock", "Crops")]
out <- setNames(agEmpl, c("Labor|Employment|Agricultural employment|+|Livestock products (mio people)",
"Labor|Employment|Agricultural employment|+|Crop products (mio people)"))
description <- paste0("Employment in agriculture (livestock+crop production) from ILO modelled estimates, ",
Expand All @@ -31,6 +32,10 @@ calcValidAgEmployment <- function(datasource = "ILO") {
stop("Datsource not available")
}


if (dataVersionILO == "") dataVersionILO <- "Aug21"
datasource <- paste(datasource, dataVersionILO, sep = "_")

out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

Expand Down
25 changes: 15 additions & 10 deletions R/calcValidHourlyLaborCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' \item USDA_FA0_raw : USDA/FAO hourly labor costs data
#' \item USDA_FA0_completed : USDA/FAO hourly labor costs data completed with a regression with GDP pc MER
#' }
#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
#'
Expand All @@ -18,31 +19,33 @@
#' }
#'

calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") {
calcValidHourlyLaborCosts <- function(datasource = "ILO_completed", dataVersionILO = "Aug23") {

if (datasource == "ILO_completed") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", fillWithRegression = TRUE,
calibYear = NULL, cutAfterCalibYear = FALSE, aggregate = FALSE)
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", dataVersionILO = dataVersionILO,
fillWithRegression = TRUE, calibYear = NULL, cutAfterCalibYear = FALSE,
aggregate = FALSE)

description <- paste("Hourly labor costs in agriculture (based on ILO data completed with a",
"regression with GDP)")

} else if (datasource == "ILO_raw") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO",
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", dataVersionILO = dataVersionILO,
fillWithRegression = FALSE, aggregate = FALSE)

description <- paste("Hourly labor costs in agriculture (based on ILO data completed with a",
"regression with GDP)")

} else if (datasource == "USDA_FAO_completed") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", fillWithRegression = TRUE,
calibYear = NULL, cutAfterCalibYear = FALSE, aggregate = FALSE)
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", dataVersionILO = dataVersionILO,
fillWithRegression = TRUE, calibYear = NULL, cutAfterCalibYear = FALSE,
aggregate = FALSE)

description <- paste("Hourly labor costs in agriculture (based on ILO data completed with a",
"regression with GDP)")

} else if (datasource == "USDA_FAO_raw") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO",
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", dataVersionILO = dataVersionILO,
fillWithRegression = FALSE, aggregate = FALSE)

description <- paste("Hourly labor costs in agriculture (based on USDA/FAO data completed with a",
Expand All @@ -54,8 +57,8 @@ calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") {
hourlyCosts <- setNames(hourlyCosts, "Labor|Wages|Hourly labor costs (USDMER05/h)")

# total hours worked as weight for aggregation to world regions
agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE, subsectors = FALSE)
weeklyHours <- calcOutput("WeeklyHoursILO", aggregate = FALSE)
agEmpl <- calcOutput("AgEmplILO", dataVersionILO = dataVersionILO, aggregate = FALSE, subsectors = FALSE)
weeklyHours <- calcOutput("WeeklyHoursILO", dataVersionILO = dataVersionILO, aggregate = FALSE)
weight <- hourlyCosts
years <- intersect(getYears(hourlyCosts, as.integer = TRUE),
intersect(getYears(agEmpl, as.integer = TRUE), getYears(weeklyHours, as.integer = TRUE)))
Expand All @@ -64,7 +67,9 @@ calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") {
as.integer = TRUE), years), ] <- agEmpl[, max(years), ] * weeklyHours[, max(years), ]
weight[hourlyCosts == 0] <- 0

# add dimensions
# USDA_FAO still depends on ILO employment
if (dataVersionILO == "") dataVersionILO <- "Aug21"
datasource <- paste(datasource, dataVersionILO, sep = "_")
out <- add_dimension(hourlyCosts, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

Expand Down
10 changes: 6 additions & 4 deletions R/calcValidTotalLaborCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#' @param datasource "USDA" (which uses FAO VoP and USDA cost shares) or "ILO" (which is based on ILO datasets and
#' calibrated to the USDA/FAO approach, but includes costs for some countries without VoP data) or "GTAP"
#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version
#'
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
Expand All @@ -14,16 +15,17 @@
#' }
#'

calcValidTotalLaborCosts <- function(datasource = "USDA") {
calcValidTotalLaborCosts <- function(datasource = "USDA", dataVersionILO = "Aug23") {

out <- calcOutput("LaborCosts", datasource = datasource, subsectors = TRUE, otherLivst = FALSE,
aggregate = FALSE)[, , c("Crops", "Livestock")]
out <- calcOutput("LaborCosts", datasource = datasource, dataVersionILO = dataVersionILO,
subsectors = TRUE, otherLivst = FALSE, aggregate = FALSE)[, , c("Crops", "Livestock")]

out <- setNames(out, c("Costs Optimization|Input Factors|Labor costs|+|Crop products (million US$05/yr)",
"Costs Optimization|Input Factors|Labor costs|+|Livestock products (million US$05/yr)"))

if (datasource == "USDA") datasource <- "USDA/FAO"
if (datasource == "ILO") datasource <- "ILO based"
if (dataVersionILO == "") dataVersionILO <- "Aug21"
if (datasource == "ILO") datasource <- paste0("ILO_", dataVersionILO, " based")
out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

Expand Down
9 changes: 7 additions & 2 deletions R/calcValidWageDevelopment.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' \item USDA_FA0_completed : based on USDA/FAO hourly labor costs data completed with a regression with GDP pc MER
#' }
#' @param baseYear year relative to which the wage development should be calculated
#' @param dataVersionILO "" for the oldest version, or "monthYear" (e.g. "Aug23") for a newer version
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
#'
Expand All @@ -19,9 +20,10 @@
#' }
#'

calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 2000) {
calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 2000, dataVersionILO = "Aug23") {

hourlyCosts <- setNames(calcOutput("ValidHourlyLaborCosts", datasource = datasource, aggregate = FALSE), NULL)
hourlyCosts <- setNames(calcOutput("ValidHourlyLaborCosts", datasource = datasource,
dataVersionILO = dataVersionILO, aggregate = FALSE), NULL)

if (!baseYear %in% getYears(hourlyCosts, as.integer = TRUE)) stop("Baseyear not available.")

Expand All @@ -35,6 +37,9 @@ calcValidWageDevelopment <- function(datasource = "ILO_completed", baseYear = 20

description <- paste("Wage index calculated as hourly labor costs in agriculture relative to 2000")

# USDA_FAO still depends on ILO employment
if (dataVersionILO == "") dataVersionILO <- "Aug21"
datasource <- paste(datasource, dataVersionILO, sep = "_")
out <- add_dimension(wageIndex, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

Expand Down
38 changes: 21 additions & 17 deletions R/fullVALIDATION.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ fullVALIDATION <- function(rev = 0.1) {
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidConsumptionValue", datasource = "FAO", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidAgEmployment", datasource = "ILO", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidAgEmployment", datasource = "ILO_FAO", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidHourlyLaborCosts", datasource = "ILO_completed", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidHourlyLaborCosts", datasource = "USDA_FAO_completed", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", baseYear = 2000,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", baseYear = 2010,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", baseYear = 2000,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", baseYear = 2010,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
for (dvILO in c("", "Aug23")) {
calcOutput(type = "ValidAgEmployment", datasource = "ILO", dataVersionILO = dvILO, aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidAgEmployment", datasource = "ILO_FAO", dataVersionILO = dvILO, aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidHourlyLaborCosts", datasource = "ILO_completed", dataVersionILO = dvILO,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidHourlyLaborCosts", datasource = "USDA_FAO_completed", dataVersionILO = dvILO,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", dataVersionILO = dvILO, baseYear = 2000,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "ILO_completed", dataVersionILO = dvILO, baseYear = 2010,
aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", dataVersionILO = dvILO,
baseYear = 2000, aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidWageDevelopment", datasource = "USDA_FAO_completed", dataVersionILO = dvILO,
baseYear = 2010, aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
}
calcOutput(type = "ValidGini", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidPovertyLine", aggregate = "REG+GLO",
Expand Down Expand Up @@ -329,7 +331,9 @@ fullVALIDATION <- function(rev = 0.1) {
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidCostsAEI", datasource = "IMPACT", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidTotalLaborCosts", datasource = "ILO", aggregate = "REG+GLO",
calcOutput(type = "ValidTotalLaborCosts", datasource = "ILO", dataVersionILO = "Aug23", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidTotalLaborCosts", datasource = "ILO", dataVersionILO = "", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidTotalLaborCosts", datasource = "USDA", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat data preparation for validation purposes

R package **mrvalidation**, version **2.55.8**
R package **mrvalidation**, version **2.55.9**

[![CRAN status](https://www.r-pkg.org/badges/version/mrvalidation)](https://cran.r-project.org/package=mrvalidation) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4317826.svg)](https://doi.org/10.5281/zenodo.4317826) [![R build status](https://github.com/pik-piam/mrvalidation/workflows/check/badge.svg)](https://github.com/pik-piam/mrvalidation/actions) [![codecov](https://codecov.io/gh/pik-piam/mrvalidation/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrvalidation) [![r-universe](https://pik-piam.r-universe.dev/badges/mrvalidation)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

To cite package **mrvalidation** in publications use:

Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi:10.5281/zenodo.4317826 <https://doi.org/10.5281/zenodo.4317826>, R package version 2.55.8, <https://github.com/pik-piam/mrvalidation>.
Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.55.9, <URL: https://github.com/pik-piam/mrvalidation>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrvalidation: madrat data preparation for validation purposes},
author = {Benjamin Leon Bodirsky and Stephen Wirth and Kristine Karstens and Florian Humpenoeder and Mishko Stevanovic and Abhijeet Mishra and Anne Biewald and Isabelle Weindl and Felicitas Beier and David Chen and Michael Crawford and Debbora Leip and Edna {Molina Bacca} and Ulrich Kreidenweis and Amsalu {W. Yalew} and Patrick {von Jeetze} and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves},
year = {2024},
note = {R package version 2.55.8},
note = {R package version 2.55.9},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
Expand Down
4 changes: 3 additions & 1 deletion man/calcValidAgEmployment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/calcValidHourlyLaborCosts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/calcValidTotalLaborCosts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/calcValidWageDevelopment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5c2e5b

Please sign in to comment.