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

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

Closed
0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q opened this issue Apr 3, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q
Copy link
Member

Originates from remindmodel/remind#1276.

calcCapital()

  • loads capital stock data from PWT
  • turns it into a capital intensity with GDP data from PWT,
  • then uses GDP data from the SSPs to calculate capital stocks again
  • (plus some convergence stuff that is inconsequential to this)

mrremind/R/calcCapital.R

Lines 21 to 28 in 8261c7f

# compute macroeconomic capital stock based on capital intensities from PWT and ssp scenarios
# t.b.d.: correct for capital stock part that enters energy sectors
capital <- readSource("PWT")[, , "rkna"]
getNames(capital) <- "kap"
capital[is.na(capital)] <- 0
gdpppp_hist <- calcOutput("GDPPast", GDPPast = "PWT", aggregate = FALSE)
#pop = calcOutput("Population", aggregate = F)
cap_intensity <- capital / setNames(gdpppp_hist, NULL)

> 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

gdpppp_hist = calcOutput("GDPPast", aggregate = FALSE)

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
Copy link
Contributor

orichters commented Apr 3, 2023

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
Copy link
Contributor

orichters commented Apr 3, 2023

My suspicion:

data <- GDPuc::convertGDP(data, "constant 2017 Int$PPP", unit, replace_NAs = c("linear", "no_conversion"))

PENN World Table data is read from this file called /p/projects/rd3mod/inputdata/sources/PWT/pwt80.xlsx, which states:

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
Copy link

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
Copy link
Contributor

orichters commented Apr 3, 2023

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
Copy link

Ok,capital intensity changes. Makes sense.

@orichters
Copy link
Contributor

solved with pik-piam/mrdrivers#67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants