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

adjust_for_inflation not suitable for deflating GDP? #25

Open
turbanisch opened this issue Apr 9, 2021 · 0 comments
Open

adjust_for_inflation not suitable for deflating GDP? #25

turbanisch opened this issue Apr 9, 2021 · 0 comments

Comments

@turbanisch
Copy link

I was trying to use priceR::adjust_for_inflation to convert US GDP values from current USD to constant 2010 USD. However, comparison with World Bank data shows that my results are way off. I wonder if this is an issue with the function or just me applying it in a way I shouldn't? I was able to manually deflate the GDP values though.

For reference, I downloaded the US GDP series in both current and constant 2010 USD from WDI. The World Bank uses GDP deflators rather than the CPI so I download both as well. Focusing on the US should eliminate any exchange rate complications.

library(tidyverse)
library(priceR)
# download data from World Bank
wdi <- WDI::WDI(
  country = "US",
  indicator = c("constant" = "NY.GDP.MKTP.KD", 
                "current" = "NY.GDP.MKTP.CD",
                "gdp_deflator" = "NY.GDP.DEFL.KD.ZG",
                "cpi_deflator" = "FP.CPI.TOTL.ZG"
  ),
  start = 1970,
  end = 2017) %>% 
  select(!iso2c:country) %>% 
  as_tibble() %>% 
  haven::zap_label()

Naively applying priceR::adjust_for_inflation does not seem to work here:

wdi %>% 
  mutate(adjusted = adjust_for_inflation(current, 2010, "US", year)) %>% 
  pivot_longer(cols = c(constant, current, adjusted), names_to = "series", values_to = "value") %>% 
  ggplot() +
    geom_line(aes(year, value, color = series))

naive

I then tried to exchange the inflation_dataframe (which apparently uses CPI) with GDP deflators but the results are almost unchanged:

# retrieve inflation data from adjust_for_inflation to modify 
inflation_dataframe <- retrieve_inflation_data("US")

# merge gdp deflator
df <- inflation_dataframe %>% 
  mutate(date = as.integer(date)) %>% 
  select(!value) %>%
  left_join(wdi %>% select(year, gdp_deflator), by = c("date" = "year")) %>% 
  rename(value = gdp_deflator)

# convert to 2010 dollars using both CPI and GDP deflators
wdi_adj <- wdi %>% 
  mutate(cpi_deflated = adjust_for_inflation(current, 2010, "US", year),
         gdp_deflated = adjust_for_inflation(current, 2010, "US", year, inflation_dataframe = df))

# plot
wdi_adj %>% 
  pivot_longer(cols = c(constant, current, cpi_deflated, gdp_deflated), names_to = "series", values_to = "value") %>% 
  ggplot(aes(year, value, color = series)) +
    geom_line()

gdp_deflated

Any help is greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant