Code
library(tidyverse)
library(ggplot2)
library(dplyr)
library(lubridate)
library(scales)
library(lmtest)
library(readxl)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Megan Galarneau
May 21, 2023
Modern technological, social, economic growth, and development would not be possible without the birth of fossil fuels (coal, oil, & gas). It plays a dominant role in our global energy systems. However, continued reliance on fossil fuel energy is the main driver of climate change today, causing detrimental planetary-scale changes to the atmosphere. While non-fossil fuel energy sources (solar, wind, & nuclear) are slowly becoming more affordable in high-income countries, it is not always a viable option for lower-income countries seeking rapid economic growth (Thunberg, G., & Peters, G., 2022).
In this paper, I ask: do local and global energy use trends vary over time by economic GDP of a country? Additionally, I seek to uncover which energy source types are more closely correlated to a country’s economic GDP than others. To answer these research questions, I will analyze the dataset, “World Energy Consumption” (2020). A case represents a country, year with corresponding economic GDP, population, fossil, non-fossil fuel energy consumption and production information.
The purpose of this paper is to analyze how different stages of economic growth and development in a country affects the types of energy consumption (fossil v. non-fossil fuel).
The dataset I will analyze is titled “World Energy Consumption” (2020). There are 223 unique countries represented with 11 types of fossil and non-fossil fuel energy sources reported on from 1965 to 2019. It contains data from 1900-2020, but energy consumption data is only available between 1965-2019. A case represents a country, year with corresponding economic GDP, population, fossil, non-fossil fuel energy consumption, and production information (17,432 rows).
Fossil Fuel
Non-Fossil Fuel
The data was collected, aggregated, and documented by Hannah Ritchie, Pablo Rosado, and Max Roser. Primary data sources include BP Statistical Review of World Energy, SHIFT Data Portal, and EMBER - Global Electricity Dashboard. Other data sources include United Nations, World Bank, Gapminder, and Maddison Project Database. The complete codebook is available here. It is published and regularly updated by Our World In Data, an organization whose mission is to “make data and research on the world’s largest problems understandable and accessible”. They make data produced by third parties available and open access. I originally found this data set on Kaggle.com by collaborator Pralabh Poudel. It was altered to standardize the names of countries and regions according to Our World in Data, recalculate primary energy in terawatt-hours, and calculate per capita figures (which are calculated from the population metric). Population figures are sourced from Gapminder and UN World Population Prospects (UNWPP).
#tidy the dataset by excluding non-countries and pivoting longer energy consumption metrics
unique_world_energy <- raw_world_energy %>%
filter(!country %in% c("Africa", "Asia Pacific", "Australia", "Eastern Africa", "Europe", "Middle Africa", "Middle East", "North America", "South & Central America", "Western Africa"))%>%
filter(!grepl("other", country, ignore.case = TRUE)) %>%
filter(year >= 1965 & year <= 2019) %>%
group_by(year) %>%
select(-contains("primary"))%>%
pivot_longer(cols = contains("consumption"),
names_to = "energy_source",
values_to = "energy_consumption") %>%
mutate(energy_source = case_when(
energy_source == "biofuel_consumption" ~ "Biofuel",
energy_source == "coal_consumption" ~ "Coal",
energy_source == "gas_consumption" ~ "Gas",
energy_source == "hydro_consumption" ~ "Hydro",
energy_source == "low_carbon_consumption" ~ "Low Carbon",
energy_source == "nuclear_consumption" ~ "Nuclear",
energy_source == "oil_consumption" ~ "Oil",
energy_source == "other_renewable_consumption" ~ "Other Renewables",
energy_source == "renewables_consumption" ~ "Renewables",
energy_source == "solar_consumption" ~ "Solar",
energy_source == "wind_consumption" ~ "Wind",
energy_source == "fossil_fuel_consumption" ~ "Fossil Fuel",
TRUE ~ energy_source
))
#dataset dimensions by rows and columns
dim(raw_world_energy)
[1] 17432 122