pik-piam / mrremind

The mrremind packages contains data preprocessing for the REMIND model.
GNU Lesser General Public License v3.0
4 stars 41 forks source link

calcCapital() results differ between 1242136 and 298465a, and nobody knows why #385

Closed 0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q closed 1 year ago

0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q commented 1 year ago

Originates from remindmodel/remind#1276.

calcCapital()

https://github.com/pik-piam/mrremind/blob/8261c7f17bf31f5d602fe19f6f9233bc8634c411/R/calcCapital.R#L21-L28

> dimSums(capital[iso3c_EUR,c(2005, 2010),], 1, TRUE) * millionDol2trillionDol
An object of class "magpie"
, , variable = kap

      year
d1        y2005    y2010
  [1,] 40.96891 45.89958
gdpppp_hist_PWT <- gdpppp_hist

https://github.com/pik-piam/mrremind/blob/8261c7f17bf31f5d602fe19f6f9233bc8634c411/R/calcCapital.R#L32

dimSums(cap_intensity[iso3c_EUR,c(2005, 2010),] * gdpppp_hist_PWT[iso3c_EUR,c(2005, 2010),], 1, TRUE) * millionDol2trillionDol
An object of class "magpie"
, , variable.variable1 = kap.gdp in constant 2005 Int$PPP

      year
d1        y2005    y2010
  [1,] 40.96891 45.89958

dimSums(cap_intensity[iso3c_EUR,c(2005, 2010),] * gdpppp_hist[iso3c_EUR,c(2005, 2010),], 1, TRUE) * millionDol2trillionDol
An object of class "magpie"
, , variable.variable1 = kap.gdp in constant 2005 Int$PPP

      year
d1        y2005    y2010
  [1,] 59.22392 66.42289

So it appears that 1242136 and 298465a used different "gdpppp_hist" for transforming capital intensities back into capital stocks. That, however, is not due to a change in calcCapital() in that timeframe.

mrdrivers moved from 0.6.6 (pik-piam/mrdrivers#49) to 0.7.2 (pik-piam/mrdrivers#54) in the meantime, so maybe answers lie that way.

orichters commented 1 year ago

Thanks, @0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q, very helpful!

This change in calcGDPPast() in mrdrivers seems to change old GDP numbers substantially:

library(tidyverse)
unit <- "constant 2005 Int$PPP"
rgdpna <- readSource("PWT")[, , "rgdpna"]

calcInternalGDPPastPWT <- function(unit) {
  data <- rgdpna
  data <- GDPuc::convertGDP(data, "constant 2017 Int$PPP", unit, replace_NAs = c("linear", "no_conversion"))
  getNames(data) <- glue("gdp in {unit}")
  list(x = data, weight = NULL, unit = "constant 2005 Int$PPP", description = "GDP from PWT")
}

calcInternalGDPPastPWTold <- function() {
  data <- rgdpna
  getNames(data) <- "GDP_PWT"
  list(x = data, weight = NULL, unit = "constant 2005 Int$PPP", description = "GDP from PWT")
}

old <- quitte::as.quitte(calcInternalGDPPastPWTold())
new <- quitte::as.quitte(calcInternalGDPPastPWT())
> filter(as.quitte(old$x), region == "DEU", period > 2004)
# A tibble: 7 × 7
  model     scenario  region variable unit      period    value
  <fct>     <fct>     <fct>  <fct>    <fct>      <int>    <dbl>
1 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2005 2614550
2 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2006 2711288.
3 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2007 2799922.
4 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2008 2830250.
5 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2009 2685143.
6 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2010 2796784.
7 (Missing) (Missing) DEU    GDP_PWT  (Missing)   2011 2881496.
> filter(as.quitte(new$x), region == "DEU", period > 2004)
# A tibble: 7 × 7
  model     scenario  region variable                     unit     period  value
  <fct>     <fct>     <fct>  <fct>                        <fct>     <int>  <dbl>
1 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2005 1.89e6
2 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2006 1.96e6
3 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2007 2.03e6
4 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2008 2.05e6
5 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2009 1.95e6
6 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2010 2.03e6
7 (Missing) (Missing) DEU    gdp in constant 2005 Int$PPP (Missin…   2011 2.09e6

So I guess this might be the reason.

orichters commented 1 year ago

My suspicion:

rgdpna: Real GDP at constant 2005 national prices (in mil. 2005US$)

So I don't think this data should be converted from 2017 to 2005 data. The PR does not show an explanation why this is the case, so I would rather revert this change.

mleimbach commented 1 year ago

Oliver, with conversion, GDP in 2005US$ becomes lower. I am still confused why we than see higher capital stocks (assuming that we apply the same capital intensity factors).

orichters commented 1 year ago

This line calculates the capital/GDP ratio based on PWT. If historical GDP is lower, then capital/GDP is higher. If you multiply that with your desired SSP2 GDP, you get a higher capital stock. So the error was in the calculation of the capital intensity factor which was inflated because of the bug.

mleimbach commented 1 year ago

Ok,capital intensity changes. Makes sense.

orichters commented 1 year ago

solved with https://github.com/pik-piam/mrdrivers/pull/67