Last updated: August 11, 2020.
This R notebook highlights the diverse economic datasets integrated into the C3.ai COVID-19 Data Lake. See the API documentation for more details.
Please contribute your questions, answers and insights on Stack Overflow. Tag c3ai-datalake
so that others can view and help build on your contributions. For support, please send email to: covid@c3.ai.
if (!require(tidyverse)) install.packages('tidyverse')
if (!require(jsonlite)) install.packages('jsonlite')
if (!require(maps)) install.packages('maps')
if (!require(mapproj)) install.packages('mapproj')
library(tidyverse)
library(jsonlite)
library(maps)
library(mapproj)
options(scipen = 999)
The following code adjusts the theme for plotting and knitting this notebook. Comment it out if you would prefer to use the standard theme or if you encounter errors.
if (!require(hrbrthemes)) install.packages('hrbrthemes')
library(hrbrthemes)
theme_set(theme_ipsum())
A number of helper functions have been created in c3aidatalake.R
for easier API calls.
We will investigate how the pandemic has affected US state economies.
states <- list(
'Alabama_UnitedStates','Alaska_UnitedStates','Arizona_UnitedStates',
'Arkansas_UnitedStates','California_UnitedStates','Colorado_UnitedStates',
'Connecticut_UnitedStates','Delaware_UnitedStates','DistrictofColumbia_UnitedStates',
'Florida_UnitedStates','Georgia_UnitedStates','Hawaii_UnitedStates',
'Idaho_UnitedStates','Illinois_UnitedStates','Indiana_UnitedStates',
'Iowa_UnitedStates','Kansas_UnitedStates','Kentucky_UnitedStates',
'Louisiana_UnitedStates','Maine_UnitedStates','Maryland_UnitedStates',
'Massachusetts_UnitedStates','Michigan_UnitedStates','Minnesota_UnitedStates',
'Mississippi_UnitedStates','Missouri_UnitedStates','Montana_UnitedStates',
'Nebraska_UnitedStates','Nevada_UnitedStates','NewHampshire_UnitedStates',
'NewJersey_UnitedStates','NewMexico_UnitedStates','NewYork_UnitedStates',
'NorthCarolina_UnitedStates','NorthDakota_UnitedStates','Ohio_UnitedStates',
'Oklahoma_UnitedStates','Oregon_UnitedStates','Pennsylvania_UnitedStates',
'PuertoRico_UnitedStates','RhodeIsland_UnitedStates','SouthCarolina_UnitedStates',
'SouthDakota_UnitedStates','Tennessee_UnitedStates','Texas_UnitedStates',
'Utah_UnitedStates','Vermont_UnitedStates','Virginia_UnitedStates',
'Washington_UnitedStates','WestVirginia_UnitedStates','Wisconsin_UnitedStates',
'Wyoming_UnitedStates'
)
The US Bureau of Economic Analysis (BEA) reports detailed data on the makeup of the US economy. Here, we will pull employment by various business sectors along with total employment. This data is reported annually.
end_date <- "2020-07-23"
employment_states <- evalmetrics(
"outbreaklocation",
list(
spec = list(
ids = states,
expressions = list(
"BEA_Employment_AccommodationAndFoodServices_Jobs",
"BEA_Employment_Accommodation_Jobs",
"BEA_Employment_AirTransportation_Jobs",
"BEA_Employment_ArtsEntertainmentAndRecreation_Jobs",
"BEA_Employment_CreditIntermediationAndRelatedActivities_Jobs",
"BEA_Employment_DataProcessingHostingAndRelatedServices_Jobs",
"BEA_Employment_EducationalServices_Jobs",
"BEA_Employment_FarmEmployment_Jobs",
"BEA_Employment_FinanceAndInsurance_Jobs",
"BEA_Employment_FoodServicesAndDrinkingPlaces_Jobs",
"BEA_Employment_GovernmentAndGovernmentEnterprises_Jobs",
"BEA_Employment_HealthCareAndSocialAssistance_Jobs",
"BEA_Employment_Hospitals_Jobs",
"BEA_Employment_Information_Jobs",
"BEA_Employment_InsuranceCarriersAndRelatedActivities_Jobs",
"BEA_Employment_Manufacturing_Jobs",
"BEA_Employment_OilAndGasExtraction_Jobs",
"BEA_Employment_RealEstateAndRentalAndLeasing_Jobs",
"BEA_Employment_RetailTrade_Jobs",
"BEA_Employment_SocialAssistance_Jobs",
"BEA_Employment_StateAndLocal_Jobs",
"BEA_Employment_TotalEmployment_Jobs",
"BEA_Employment_TransitAndGroundPassengerTransportation_Jobs",
"BEA_Employment_TransportationAndWarehousing_Jobs",
"BEA_Employment_TruckTransportation_Jobs",
"BEA_Employment_WarehousingAndStorage_Jobs"
),
start = "2015-01-01",
end = end_date,
interval = "YEAR"
)
),
get_all = TRUE
) %>%
filter(missing == 0) %>%
select(-missing) %>%
mutate(state = str_replace(name, '_UnitedStates', ''))
The US Bureau of Labor Statistics reports measures including the size of the labor force and the unemployment rate monthly. Let’s request unemployment rates at a state level along with confirmed COVID-19 case counts provided by Johns Hopkins University.
unemployment_states <- evalmetrics(
"outbreaklocation",
list(
spec = list(
ids = states,
expressions = list(
"BLS_UnemploymentRate",
"JHU_ConfirmedCases"
),
start = "2018-01-01",
end = end_date,
interval = "MONTH"
)
),
get_all = TRUE
) %>%
filter(missing == 0) %>%
select(-missing) %>%
mutate(state = str_replace(name, '_UnitedStates', ''))
We can begin by exploring how COVID-19 case counts have grown in US states.
high_case_states <- unemployment_states %>%
filter(dates == '2020-07-01') %>%
filter(value_id == 'JHU_ConfirmedCases') %>%
filter(data > 1e5) %>%
pull(name)
unemployment_states %>%
filter(value_id == 'JHU_ConfirmedCases') %>%
filter(dates >= '2020-02-01') %>%
filter(name %in% high_case_states) %>%
ggplot() + geom_line(aes(x = dates, y = data, colour = state)) +
labs(
x='Date',
y='Cumulative Case Count',
title='Cumulative Case Counts by State',
colour='State'
) +
theme(legend.position = "bottom")