Skip to content

Commit

Permalink
updated wage validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Debbora Leip committed Oct 9, 2023
1 parent 24b718b commit da44fcd
Show file tree
Hide file tree
Showing 10 changed files with 97 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: '49342278'
ValidationKey: '49392085'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9019
rev: v0.3.2.9021
hooks:
- id: parsable-R
- id: deps-in-desc
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.51.4
date-released: '2023-09-27'
version: 2.51.5
date-released: '2023-10-09'
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.51.4
Date: 2023-09-27
Version: 2.51.5
Date: 2023-10-09
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
57 changes: 45 additions & 12 deletions R/calcValidHourlyLaborCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,69 @@
#'
#' @description hourly labor costs in crop+livestock production
#'
#' @param datasource So far only "ILO_completed" (based on regression between ILO hourly labor costs and GDP pc MER,
#' calibrated to match USDA/FAO total labor costs)
#'
#' @param datasource Available datasources are:
#' \itemize{
#' \item ILO_raw : ILO hourly labor costs data
#' \item ILO_completed : ILO hourly labor costs data completed with a regression with GDP pc MER
#' \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
#' }
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
#'
#' @examples
#' \dontrun{
#' calcOutput("ValidHourlyLaborCosts", datasource="ILO_completed")
#' calcOutput("ValidHourlyLaborCosts", datasource = "ILO_completed")
#' }
#'

calcValidHourlyLaborCosts <- function(datasource = "ILO_completed") {

if (datasource == "ILO_completed") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", aggregate = FALSE)
hourlyCosts <- setNames(hourlyCosts, "Labor|Wages|Hourly labor costs (USDMER05/h)")
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO", 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)")

# total hours worked in 2010 as weight for aggregation to world regions
agEmpl <- calcOutput("AgEmplILO", aggregate = FALSE, subsectors = FALSE)
weeklyHours <- calcOutput("WeeklyHoursILO", aggregate = FALSE)
weight <- hourlyCosts
weight[, , ] <- agEmpl[, 2010, ] * weeklyHours[, 2010, ]
} else if (datasource == "ILO_raw") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "ILO",
fillWithRegression = FALSE, aggregate = FALSE)

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

} else if (datasource == "USDA_FAO_completed") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", 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",
fillWithRegression = FALSE, aggregate = FALSE)

description <- paste("Hourly labor costs in agriculture (based on USDA/FAO data completed with a",
"regression with GDP)")
} else {
stop("Datsource not available")
}

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)
weight <- hourlyCosts
years <- intersect(getYears(hourlyCosts, as.integer = TRUE),
intersect(getYears(agEmpl, as.integer = TRUE), getYears(weeklyHours, as.integer = TRUE)))
weight[, years, ] <- agEmpl[, years, ] * weeklyHours[, years, ]
weight[, setdiff(getYears(hourlyCosts,
as.integer = TRUE), years), ] <- agEmpl[, max(years), ] * weeklyHours[, max(years), ]
weight[hourlyCosts == 0] <- 0

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

Expand Down
32 changes: 16 additions & 16 deletions R/calcValidWageDevelopment.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
#'
#' @description wage index: hourly labor costs in crop+livestock production relative to a baseyear
#'
#' @param datasource So far only "ILO_completed" (based on regression between ILO hourly labor costs and GDP pc MER,
#' calibrated to match USDA/FAO total labor costs)
#' @param datasource Available datasources are:
#' \itemize{
#' \item ILO_raw : based on ILO hourly labor costs data
#' \item ILO_completed : based on ILO hourly labor costs data completed with a regression with GDP pc MER
#' \item USDA_FA0_raw : based on USDA/FAO hourly labor costs data
#' \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
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author Debbora Leip
Expand All @@ -16,24 +21,19 @@

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

if (datasource == "ILO_completed") {
hourlyCosts <- calcOutput("HourlyLaborCosts", datasource = "USDA_FAO", aggregate = FALSE)
hourlyCosts <- setNames(calcOutput("ValidHourlyLaborCosts", datasource = datasource, aggregate = FALSE), NULL)

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

wageIndex <- collapseDim(hourlyCosts / hourlyCosts[, baseYear, ], dim = 2.2)
wageIndex <- setNames(wageIndex, paste0("Labor|Wages|Hourly labor costs relative to ", baseYear, " (index)"))
wageIndex <- collapseDim(hourlyCosts / hourlyCosts[, baseYear, ], dim = 2.2)
wageIndex <- setNames(wageIndex, paste0("Labor|Wages|Hourly labor costs relative to ", baseYear, " (index)"))

# population in 2000 as weight for aggregation to world regions and globally
weight <- wageIndex
weight[, , ] <- calcOutput("Population", naming = "scenario",
aggregate = FALSE, years = c(baseYear))[, , "SSP2", drop = TRUE]
# population in 2000 as weight for aggregation to world regions and globally
weight <- wageIndex
weight[, , ] <- calcOutput("Population", naming = "scenario",
aggregate = FALSE, years = c(baseYear))[, , "SSP2", drop = TRUE]

description <- paste("Wage index calculated as hourly labor costs in agriculture relative to 2000 (based on ILO",
"data completed with a regression with GDP, calibrated using USDA and FAO data)")
} else {
stop("Datsource not available")
}
description <- paste("Wage index calculated as hourly labor costs in agriculture relative to 2000")

out <- add_dimension(wageIndex, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)
Expand Down
18 changes: 12 additions & 6 deletions R/fullVALIDATION.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
fullVALIDATION <- function(rev = 0.1) {

if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.63 anymore.
if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.63 anymore.
Please use a older snapshot/version of the library, if you need older revisions.")
# all validation data regional aggregations happens here
# for the first variable output calculation, append paramenter should be set to FALSE so that the
Expand Down Expand Up @@ -43,10 +43,16 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.
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)
calcOutput(type = "ValidGini", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidPovertyLine", aggregate = "REG+GLO",
Expand Down Expand Up @@ -80,9 +86,9 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.
append = TRUE, try = TRUE) # ready
calcOutput(type = "ValidTrade", aggregate = "REG+GLO", file = valfile,
append = TRUE, net_trade = FALSE, equalized = FALSE, try = TRUE) # ready
calcOutput(type = "ValidTrade", aggregate = "REG+GLO",
datasource = "FAOBilateral", file = valfile,
append = TRUE, try = TRUE) # ready
calcOutput(type = "ValidTrade", aggregate = "REG+GLO",
datasource = "FAOBilateral", file = valfile,
append = TRUE, try = TRUE) # ready
calcOutput(type = "ValidTrade", aggregate = "REG+GLO",
datasource = "FAOBilateral", file = valfile,
append = TRUE, net_trade = FALSE, equalized = FALSE, try = TRUE) # ready
Expand Down Expand Up @@ -265,7 +271,7 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.
calcOutput(type = "ValidTauPastr", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidLSUdensity", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidAgriResearchIntensity", aggregate = "REG+GLO", datasource = "Pardey",
file = valfile, append = TRUE, try = TRUE)
file = valfile, append = TRUE, try = TRUE)

# Prices
calcOutput(type = "ValidPriceAgriculture", datasource = "WBGEM", aggregate = FALSE,
Expand Down Expand Up @@ -318,7 +324,7 @@ if (rev < 4.66) stop("mrvalidation(>= 2.34.0) does not support revision below 4.
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidTotalLaborCosts", datasource = "GTAP", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)
calcOutput(type = "ValidCostsTransport", datasource = "GTAPwholesale", aggregate = "REG+GLO",
calcOutput(type = "ValidCostsTransport", datasource = "GTAPwholesale", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE)

# Diversity indices
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.51.4**
R package **mrvalidation**, version **2.51.5**

[![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, Humpenoeder F, von Jeetze P, Wang X, Dietrich J, Alves M (2023). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.51.4, <URL: 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, Humpenoeder F, von Jeetze P, Wang X, Dietrich J, Alves M (2023). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.51.5, <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 Florian {Humpenoeder } and Patrick {von Jeetze } and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves},
year = {2023},
note = {R package version 2.51.4},
note = {R package version 2.51.5},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
Expand Down
11 changes: 8 additions & 3 deletions man/calcValidHourlyLaborCosts.Rd

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

9 changes: 7 additions & 2 deletions man/calcValidWageDevelopment.Rd

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

0 comments on commit da44fcd

Please sign in to comment.