<p>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 <em>price level</em> inflation measures the change in price level.</p>
<p>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 <span class="math-container">$rGDP = nGDP/Def$</span> or <span class="math-container">$ rGDP = nGDP/(CPI/100)$</span>.</p>
<p>Inflation is defined as positive change in CPI, <span class="math-container">$\pi = (CPI_t=CPI_{t-1})/CPI_{t-1}$</span> 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.</p>

CC BY-SA 4.0
2024-06-03T16:48:04.043Z
I have found [A Global Database of Inflation](https://www.worldbank.org/en/research/brief/inflation-database), 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.
At_my_wits_end_99
CC BY-SA 4.0
2024-06-03T18:36:30.343Z
@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
1muflon1
CC BY-SA 4.0
2024-06-04T13:16:33.063Z
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.
At_my_wits_end_99
CC BY-SA 4.0
2024-06-02T21:37:25.583Z
2024-06-02T21:37:25.583Z
1muflon1
<p>I am attempting to calculate (in R) the global <em>real</em> GDP using what I assume is the <a href="https://data.worldbank.org/indicator/NY.GDP.MKTP.CD?end=2022&amp;start=1981" rel="nofollow noreferrer">nominal GDP from the World Bank</a> and what I can only identify as the <a href="https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG%20?end=2022&amp;start=1981" rel="nofollow noreferrer">inflation rate, also from the World bank</a>.</p>
<p>Unfortunately I am unable to get reasonable results using my calculation method, and I cannot identify the specific cause:</p>
<ol>
<li>The inflation data is not meant to be used in this way.</li>
<li>I have committed a logical or mathematical error.</li>
</ol>
<p>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.</p>
<pre><code>adjust_for_inflation &lt;- function(nominal_gdp, inflation_rate, base_year) {
  # Get the time indices
  time_indices &lt;- time(nominal_gdp)
 
  # Calculate the cumulative inflation rate up to each year
  cumulative_inflation &lt;- cumprod(1 + inflation_rate / 100)
  
  # Find the cumulative inflation rate for the base year
  base_year_index &lt;- which(time_indices == base_year)
  base_year_cumulative_inflation &lt;- cumulative_inflation[base_year_index]
  
  # Normalize cumulative inflation rates so that the base year's rate is 1
  normalized_cumulative_inflation &lt;- cumulative_inflation / base_year_cumulative_inflation
  
  # Adjust nominal GDP to real GDP based on the normalized cumulative inflation
  real_gdp &lt;- 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 &lt;- ts(real_gdp, start=start(nominal_gdp), frequency=frequency(nominal_gdp))
  
  return(real_gdp_ts)
}
</code></pre>
<p>This seems well and good, and testing it on some made up data produces exactly the results I intended.</p>
<pre><code>nominal_gdp &lt;- ts(c(100, 100, 100, 100, 100), start=2018, frequency=1)
inflation_rate &lt;- ts(c(10, 10, 10, 10, 10), start=2018, frequency=1)
base_year &lt;- 2020
adjusted_gdp &lt;- adjust_for_inflation(nominal_gdp, inflation_rate, base_year)
</code></pre>
<pre><code>  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
</code></pre>
<p>However, when plugging in the data from the World Bank, the result essentially indicates that real GDP has stagnated for the last 4 decades</p>
<pre><code>nominal_gdp_raw &lt;- ts(t(read_excel('world_bank_nominal.xls', col_names = FALSE)), start=1960)[,1]
nominal_gdp &lt;- window(nominal_gdp_raw , start = 1981)
inflation_rate &lt;- ts(t(read_excel(&quot;world_bank_inflation_rate.xlsx&quot;, col_names = FALSE))[,1], start=1981)
base_year &lt;- 2022

adjusted_gdp &lt;- 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)
</code></pre>
<p><a href="https://imgur.com/a/yJcJYs2" rel="nofollow noreferrer">Link to plot</a></p>
<p>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 <code>cumulative_inflation &lt;- 1 + cumsum(inflation_rate / 100)</code> and it <a href="https://imgur.com/a/4ss3kI2" rel="nofollow noreferrer">has more rational seeming results</a>, but I can't justify why it would be a cumulative sum instead of compounding percentages.</p>

CC BY-SA 4.0
2024-06-02T19:59:57.150Z
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?
Adam Bailey
CC BY-SA 4.0
2024-06-03T16:55:50.483Z
@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?
At_my_wits_end_99
CC BY-SA 4.0
2024-06-03T18:45:06.930Z
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.
Adam Bailey
<macroeconomics><mathematical-economics><inflation><gdp><r>
Can global real GDP be calculated using nominal GDP and inflation rate? If so what is the error?
At_my_wits_end_99
# Can global real GDP be calculated using nominal GDP and inflation rate? If so what is the error?

(Asked by: username_0 on 2024-06-02)

I am attempting to calculate (in R) the global *real* GDP using what I assume is the [nominal GDP from the World Bank](https://data.worldbank.org/indicator/NY.GDP.MKTP.CD?end=2022&start=1981) and what I can only identify as the [inflation rate, also from the World bank](https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG%20?end=2022&start=1981).

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](https://imgur.com/a/yJcJYs2)

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](https://imgur.com/a/4ss3kI2), but I can't justify why it would be a cumulative sum instead of compounding percentages.

**Tags:** macroeconomics, mathematical-economics, inflation, gdp, r

> **Comments:**
> **username_1**: 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?  
> **username_0**: @username_1 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?  
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2024-06-02. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_0**: I have found [A Global Database of Inflation](https://www.worldbank.org/en/research/brief/inflation-database), 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 username_1 username_1'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.  
> **username_2**: @username_0 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  
> **username_0**: 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.  

---

