1
$\begingroup$

I am attempting to calculate (in R) the global real GDP using what I assume is the nominal GDP from the World Bank and what I can only identify as the inflation rate, also from the World bank.

Unfortunately I am unable to get reasonable results using my calculation method, and I cannot identify the specific cause:

  1. The inflation data is not meant to be used in this way.
  2. I have committed a logical or mathematical error.

The most logical way (for me) to do this is to calculate the cumulative product of all the inflation rates, then normalize them around the chosen base year.

adjust_for_inflation <- function(nominal_gdp, inflation_rate, base_year) {
  # Get the time indices
  time_indices <- time(nominal_gdp)
 
  # Calculate the cumulative inflation rate up to each year
  cumulative_inflation <- cumprod(1 + inflation_rate / 100)
  
  # Find the cumulative inflation rate for the base year
  base_year_index <- which(time_indices == base_year)
  base_year_cumulative_inflation <- cumulative_inflation[base_year_index]
  
  # Normalize cumulative inflation rates so that the base year's rate is 1
  normalized_cumulative_inflation <- cumulative_inflation / base_year_cumulative_inflation
  
  # Adjust nominal GDP to real GDP based on the normalized cumulative inflation
  real_gdp <- nominal_gdp / normalized_cumulative_inflation
  
  # Print statements for debugging
  print(data.frame(Year = time_indices, Nominal_GDP = nominal_gdp, Inflation_Rate = inflation_rate, Cumulative_Inflation = cumulative_inflation, Normalized_Cumulative_Inflation = normalized_cumulative_inflation, Real_GDP = real_gdp))
  
  # Return the real GDP as a ts object with the same time indices
  real_gdp_ts <- ts(real_gdp, start=start(nominal_gdp), frequency=frequency(nominal_gdp))
  
  return(real_gdp_ts)
}

This seems well and good, and testing it on some made up data produces exactly the results I intended.

nominal_gdp <- ts(c(100, 100, 100, 100, 100), start=2018, frequency=1)
inflation_rate <- ts(c(10, 10, 10, 10, 10), start=2018, frequency=1)
base_year <- 2020
adjusted_gdp <- adjust_for_inflation(nominal_gdp, inflation_rate, base_year)
  Year Nominal_GDP Inflation_Rate Cumulative_Inflation Normalized_Cumulative_Inflation  Real_GDP
1 2018         100             10              1.10000                       0.8264463 121.00000
2 2019         100             10              1.21000                       0.9090909 110.00000
3 2020         100             10              1.33100                       1.0000000 100.00000
4 2021         100             10              1.46410                       1.1000000  90.90909
5 2022         100             10              1.61051                       1.2100000  82.64463

However, when plugging in the data from the World Bank, the result essentially indicates that real GDP has stagnated for the last 4 decades

nominal_gdp_raw <- ts(t(read_excel('world_bank_nominal.xls', col_names = FALSE)), start=1960)[,1]
nominal_gdp <- window(nominal_gdp_raw , start = 1981)
inflation_rate <- ts(t(read_excel("world_bank_inflation_rate.xlsx", col_names = FALSE))[,1], start=1981)
base_year <- 2022

adjusted_gdp <- adjust_for_inflation(nominal_gdp, inflation_rate, base_year)

plot.ts(adjusted_gdp/10^9, ylim = c(0,max(adjusted_gdp/10^9))*1.1)

Link to plot

This is obviously wrong, and useless, however I genuinely cannot figure out what I did wrong. I also tried a cumulative sum approach to it cumulative_inflation <- 1 + cumsum(inflation_rate / 100) and it has more rational seeming results, but I can't justify why it would be a cumulative sum instead of compounding percentages.

$\endgroup$
3
  • $\begingroup$ If I understand correctly, following the links in your first sentence, nominal GDP is world GDP at current US prices, while inflation is average world inflation. Don't you need US inflation instead? $\endgroup$ Commented Jun 2 at 19:59
  • $\begingroup$ @AdamBailey I am getting mixed messages, so you are indeed in favor of using Inflation rate to calculate real GDP, consumer prices (annual %), but using the Unites States inflation instead of Global? $\endgroup$ Commented Jun 3 at 16:55
  • $\begingroup$ I wouldn't claim to be too familiar with the differences between measures such as CPI, deflator, etc. What I am saying is that if you start, as you appear to do, from world GDP at current US prices, and you want to get to real world GDP, then you need to adjust using an appropriate measure relating to the US rather than one relating to the whole world. $\endgroup$ Commented Jun 3 at 18:45

1 Answer 1

0
$\begingroup$

Inflation is not meant to be used that way. If you want to calculate real GDP you want either deflator or CPI or some measure of price level inflation measures the change in price level.

What you want is to take nominal GDP and divide it by either deflator or price index (which should also be divided by 100). So you want either $rGDP = nGDP/Def$ or $ rGDP = nGDP/(CPI/100)$.

Inflation is defined as positive change in CPI, $\pi = (CPI_t=CPI_{t-1})/CPI_{t-1}$ you can't calculate CPI from inflation data unless you know CPI at least in one year and if you know that you probably have dataset of CPI for other years. However, I would be extremely surprised if WB would not have data for world CPI or deflator. You should look for it.

$\endgroup$
3
  • $\begingroup$ I have found A Global Database of Inflation, and in the Excel downloadable data, in the Aggregate sheet, there are various CPI inflation (percent) series, and a GDP deflator growth rate (percent), i will proceed to test my data with the deflator growth rate. Also, what do you think about Adam Bailey's question/suggestion, that I should simply use the inflation of the United States? He posed it as a question, one I can't assuredly answer. $\endgroup$ Commented Jun 3 at 16:48
  • $\begingroup$ @At_my_wits_end_99 you should be using deflator not growth rate of deflator. Growth rate of deflator is just another measure of rate of inflation, but to correct GDP for inflation you need measure of price level $\endgroup$
    – 1muflon1
    Commented Jun 3 at 18:36
  • $\begingroup$ I have concluded that you are correct, i abandoned the inflation idea, and in the absence of the deflator itself, I used the GDP constant 2015 US and GDP current US to calculate the deflator based in 2015, and then rebased it by normalizing it to the deflator value of the new base year, then applied the new deflator to the nominal GDP, many thanks. $\endgroup$ Commented Jun 4 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.