Analysis Question

Which major economies experienced the largest increase in GDP between 2007 and 2017?

Import the Data

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
gdp <- read_csv("gdp.csv")
## Rows: 264 Columns: 60
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): Country Name, Country Code
## dbl (58): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(gdp)
## # A tibble: 6 × 60
##   `Country Name` `Country Code`   `1960`  `1961`  `1962`  `1963`  `1964`  `1965`
##   <chr>          <chr>             <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1 Aruba          ABW             NA      NA      NA      NA      NA      NA     
## 2 Afghanistan    AFG              5.38e8  5.49e8  5.47e8  7.51e8  8.00e8  1.01e9
## 3 Angola         AGO             NA      NA      NA      NA      NA      NA     
## 4 Albania        ALB             NA      NA      NA      NA      NA      NA     
## 5 Andorra        AND             NA      NA      NA      NA      NA      NA     
## 6 Arab World     ARB             NA      NA      NA      NA      NA      NA     
## # ℹ 52 more variables: `1966` <dbl>, `1967` <dbl>, `1968` <dbl>, `1969` <dbl>,
## #   `1970` <dbl>, `1971` <dbl>, `1972` <dbl>, `1973` <dbl>, `1974` <dbl>,
## #   `1975` <dbl>, `1976` <dbl>, `1977` <dbl>, `1978` <dbl>, `1979` <dbl>,
## #   `1980` <dbl>, `1981` <dbl>, `1982` <dbl>, `1983` <dbl>, `1984` <dbl>,
## #   `1985` <dbl>, `1986` <dbl>, `1987` <dbl>, `1988` <dbl>, `1989` <dbl>,
## #   `1990` <dbl>, `1991` <dbl>, `1992` <dbl>, `1993` <dbl>, `1994` <dbl>,
## #   `1995` <dbl>, `1996` <dbl>, `1997` <dbl>, `1998` <dbl>, `1999` <dbl>, …

I imported the World Bank GDP dataset and viewed the first few rows of the data.

Calculate GDP Change

gdp$diff <- gdp$"2017" - gdp$"2007"
head(gdp)
## # A tibble: 6 × 61
##   `Country Name` `Country Code`   `1960`  `1961`  `1962`  `1963`  `1964`  `1965`
##   <chr>          <chr>             <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1 Aruba          ABW             NA      NA      NA      NA      NA      NA     
## 2 Afghanistan    AFG              5.38e8  5.49e8  5.47e8  7.51e8  8.00e8  1.01e9
## 3 Angola         AGO             NA      NA      NA      NA      NA      NA     
## 4 Albania        ALB             NA      NA      NA      NA      NA      NA     
## 5 Andorra        AND             NA      NA      NA      NA      NA      NA     
## 6 Arab World     ARB             NA      NA      NA      NA      NA      NA     
## # ℹ 53 more variables: `1966` <dbl>, `1967` <dbl>, `1968` <dbl>, `1969` <dbl>,
## #   `1970` <dbl>, `1971` <dbl>, `1972` <dbl>, `1973` <dbl>, `1974` <dbl>,
## #   `1975` <dbl>, `1976` <dbl>, `1977` <dbl>, `1978` <dbl>, `1979` <dbl>,
## #   `1980` <dbl>, `1981` <dbl>, `1982` <dbl>, `1983` <dbl>, `1984` <dbl>,
## #   `1985` <dbl>, `1986` <dbl>, `1987` <dbl>, `1988` <dbl>, `1989` <dbl>,
## #   `1990` <dbl>, `1991` <dbl>, `1992` <dbl>, `1993` <dbl>, `1994` <dbl>,
## #   `1995` <dbl>, `1996` <dbl>, `1997` <dbl>, `1998` <dbl>, `1999` <dbl>, …

I created a new variable called diff to measure the change in GDP from 2007 to 2017.

Select Major Economies

major_economies <- subset(gdp,
  `Country Name` == "United States" |
  `Country Name` == "China" |
  `Country Name` == "Japan" |
  `Country Name` == "Germany" |
  `Country Name` == "United Kingdom" |
  `Country Name` == "France" |
  `Country Name` == "India" |
  `Country Name` == "Brazil" |
  `Country Name` == "Canada" |
  `Country Name` == "Italy" |
  `Country Name` == "Australia" |
  `Country Name` == "Spain" |
  `Country Name` == "Mexico" |
  `Country Name` == "Indonesia" |
  `Country Name` == "Korea, Rep."
)

major_economies
## # A tibble: 15 × 61
##    `Country Name` `Country Code`      `1960`   `1961`   `1962`   `1963`   `1964`
##    <chr>          <chr>                <dbl>    <dbl>    <dbl>    <dbl>    <dbl>
##  1 Australia      AUS                1.86e10  1.96e10  1.99e10  2.15e10  2.38e10
##  2 Brazil         BRA                1.52e10  1.52e10  1.99e10  2.30e10  2.12e10
##  3 Canada         CAN                4.11e10  4.08e10  4.20e10  4.47e10  4.89e10
##  4 China          CHN                5.97e10  5.01e10  4.72e10  5.07e10  5.97e10
##  5 Germany        DEU               NA       NA       NA       NA       NA      
##  6 Spain          ESP                1.21e10  1.38e10  1.61e10  1.91e10  2.13e10
##  7 France         FRA                6.27e10  6.83e10  7.63e10  8.56e10  9.49e10
##  8 United Kingdom GBR                7.23e10  7.67e10  8.06e10  8.54e10  9.34e10
##  9 Indonesia      IDN               NA       NA       NA       NA       NA      
## 10 India          IND                3.65e10  3.87e10  4.16e10  4.78e10  5.57e10
## 11 Italy          ITA                4.04e10  4.48e10  5.04e10  5.77e10  6.32e10
## 12 Japan          JPN                4.43e10  5.35e10  6.07e10  6.95e10  8.17e10
## 13 Korea, Rep.    KOR                3.96e 9  2.42e 9  2.81e 9  3.99e 9  3.46e 9
## 14 Mexico         MEX                1.30e10  1.42e10  1.52e10  1.70e10  2.01e10
## 15 United States  USA                5.43e11  5.63e11  6.05e11  6.39e11  6.86e11
## # ℹ 54 more variables: `1965` <dbl>, `1966` <dbl>, `1967` <dbl>, `1968` <dbl>,
## #   `1969` <dbl>, `1970` <dbl>, `1971` <dbl>, `1972` <dbl>, `1973` <dbl>,
## #   `1974` <dbl>, `1975` <dbl>, `1976` <dbl>, `1977` <dbl>, `1978` <dbl>,
## #   `1979` <dbl>, `1980` <dbl>, `1981` <dbl>, `1982` <dbl>, `1983` <dbl>,
## #   `1984` <dbl>, `1985` <dbl>, `1986` <dbl>, `1987` <dbl>, `1988` <dbl>,
## #   `1989` <dbl>, `1990` <dbl>, `1991` <dbl>, `1992` <dbl>, `1993` <dbl>,
## #   `1994` <dbl>, `1995` <dbl>, `1996` <dbl>, `1997` <dbl>, `1998` <dbl>, …

I selected 15 major economies to compare their GDP changes while excluding regional and income-group aggregates in the dataset.

GDP Change in Trillions

major_economies$diff_trillion <- major_economies$diff / 1000000000000

major_economies[, c("Country Name", "diff_trillion")]
## # A tibble: 15 × 2
##    `Country Name` diff_trillion
##    <chr>                  <dbl>
##  1 Australia             0.471 
##  2 Brazil                0.658 
##  3 Canada                0.188 
##  4 China                 8.69  
##  5 Germany               0.237 
##  6 Spain                -0.168 
##  7 France               -0.0747
##  8 United Kingdom       -0.452 
##  9 Indonesia             0.583 
## 10 India                 1.40  
## 11 Italy                -0.268 
## 12 Japan                 0.357 
## 13 Korea, Rep.           0.408 
## 14 Mexico                0.0972
## 15 United States         4.91

I converted the GDP change to trillions of US dollars to make the results easier to interpret.

Summary Statistics

summarize(major_economies, average_growth = mean(diff_trillion, na.rm = TRUE), maximum_growth = max(diff_trillion, na.rm = TRUE), minimum_growth = min(diff_trillion, na.rm = TRUE))
## # A tibble: 1 × 3
##   average_growth maximum_growth minimum_growth
##            <dbl>          <dbl>          <dbl>
## 1           1.14           8.69         -0.452

I used summarize() to calculate the average, maximum, and minimum GDP changes among the selected economies.

GDP Increase Above $1 Trillion

large_growth <- subset(major_economies, diff > 1000000000000)
large_growth[, c("Country Name", "diff_trillion")]
## # A tibble: 3 × 2
##   `Country Name` diff_trillion
##   <chr>                  <dbl>
## 1 China                   8.69
## 2 India                   1.40
## 3 United States           4.91
nrow(large_growth)
## [1] 3

I identified the major economies whose GDP increased by more than $1 trillion.

Count the Increase Groups

major_economies$growth_group <-  ifelse(major_economies$diff > 1000000000000, "Over $1 Trillion", "Under $1 Trillion")
count(major_economies, growth_group)
## # A tibble: 2 × 2
##   growth_group          n
##   <chr>             <int>
## 1 Over $1 Trillion      3
## 2 Under $1 Trillion    12

I used count() to compare how many major economies had GDP increases above or below $1 trillion.

Grouped Analysis

gdp_grouped <- group_by(major_economies, growth_group)
summarize(gdp_grouped, average_growth = mean(diff_trillion, na.rm = TRUE))
## # A tibble: 2 × 2
##   growth_group      average_growth
##   <chr>                      <dbl>
## 1 Over $1 Trillion           5.00 
## 2 Under $1 Trillion          0.170

I used group_by() and summarize() to compare the average GDP change between the two groups.

Rank GDP Increase

sort_growth <- major_economies[ order(major_economies$diff, decreasing = TRUE), ]
sort_growth[, c("Country Name", "diff_trillion")]
## # A tibble: 15 × 2
##    `Country Name` diff_trillion
##    <chr>                  <dbl>
##  1 China                 8.69  
##  2 United States         4.91  
##  3 India                 1.40  
##  4 Brazil                0.658 
##  5 Indonesia             0.583 
##  6 Australia             0.471 
##  7 Korea, Rep.           0.408 
##  8 Japan                 0.357 
##  9 Germany               0.237 
## 10 Canada                0.188 
## 11 Mexico                0.0972
## 12 France               -0.0747
## 13 Spain                -0.168 
## 14 Italy                -0.268 
## 15 United Kingdom       -0.452

Visualization

ggplot(major_economies, aes(x = reorder(`Country Name`, diff_trillion), y = diff_trillion)) +
  geom_col() +
  coord_flip() +
  labs(title = "GDP Change Across Major Economies, 2007–2017", x = "Country", y = "GDP Change (Trillion US$)")

Key Insights

  1. China experienced the largest GDP increase among the selected major economies, followed by the United States and India.

  2. Only 3 of the 15 selected major economies (China, the United States, and India) experienced GDP increases of more than $1 trillion between 2007 and 2017.