GDP by Industry - GDPbyIndustry

Data - BEA

Last data update: 25 juil. 2026, 12:36

Last compile: 04 sept. 2026, 23:41

List of Parameters

Code
paste0("https://apps.bea.gov/api/data/?&",
       "UserID=", bea_key, "&",
       "method=GetParameterList&",
       "DataSetName=GDPbyIndustry&") |>
  fromJSON() |>
  pluck("BEAAPI", "Results", "Parameter") |> 
  select(ParameterName, ParameterDataType, ParameterDescription) %>%
  {if (is_html_output()) print_table(.) else .}
ParameterName ParameterDataType ParameterDescription
Frequency string A - Annual, Q-Quarterly
Industry string List of industries to retrieve (ALL for All)
TableID integer The unique GDP by Industry table identifier (ALL for All)
Year integer List of year(s) of data to retrieve (ALL for All)

List of Tables

Code
paste0("https://apps.bea.gov/api/data/?&",
       "UserID=", bea_key, "&",
       "method=GetParameterValues&",
       "datasetname=GDPbyIndustry&",
       "ParameterName=TableID&") |>
  fromJSON() |>
  pluck("BEAAPI", "Results", "ParamValue") |>
  select(Key, Desc) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

Ex 1

Code
paste0("https://apps.bea.gov/api/data/?&",
       "UserID=", bea_key, "&",
       "method=GetData&",
       "DataSetName=GDPbyIndustry&",
       "TableID=15&",
       "Frequency=A&",
       "Industry=ALL&",
       "Year=ALL&",
       "ResultFormat=JSON") |>
  fromJSON() |> 
  pluck("BEAAPI", "Results", "Data") |> 
  nth(1) |>
  select(Industry, IndustrYDescription, Year, DataValue) %>%
  mutate_at(vars(DataValue), funs(gsub(",", "", .) |> as.numeric())) |>
  mutate(date = Year |> paste0("-01-01") |> as.Date()) |>
  select(Industry, IndustrYDescription, date, DataValue) |>
  arrange(date, Industry) |>
  filter(date == as.Date("2018-01-01")) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

Ex 2

Code
paste0("https://apps.bea.gov/api/data/?&",
       "UserID=", bea_key, "&",
       "method=GetData&",
       "DataSetName=GDPbyIndustry&",
       "TableID=15&",
       "Frequency=A&",
       "Industry=ALL&",
       "Year=ALL&",
       "ResultFormat=JSON") |>
  fromJSON() |> 
  pluck("BEAAPI", "Results", "Data") |> 
  nth(1) |>
  select(TableID, Year, Industry, IndustrYDescription, DataValue) %>%
  mutate_at(vars(DataValue), funs(gsub(",", "", .) |> as.numeric())) |>
  mutate(date = Year |> paste0("-01-01") |> as.Date()) |>
  filter(Industry %in% c("11", "31G", "6", "7")) |>
  rename(variable = IndustrYDescription) |>
  left_join(gdp_adjustment, by = "date") |>
  mutate(value = 1000 * `Real GDP / Real GDP Trend (Log Linear)` * DataValue / GDP) |>
  ggplot() + geom_line(aes(x = date, y = value, color = variable)) + 
  ylab("% of GDP") + xlab("") + 
  theme_minimal()+
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1927-01-01")),
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf), 
            fill = 'grey', alpha = 0.5) +
  scale_x_date(breaks = nber_recessions$Peak,
               minor_breaks = "5 years",
               labels = date_format("%Y"),
               limits = c(1997, Inf) |> paste0("-01-01") |> as.Date()) + 
  scale_y_continuous(breaks = 0.01*seq(0, 160, 2),
                     labels = scales::percent_format(accuracy = 1)) +
  scale_color_manual(values = viridis(5)[1:4]) +
  theme(legend.position = c(0.7, 0.9),
        legend.title = element_blank(),
        legend.text = element_text(size = 8),
        legend.key.size = unit(0.9, 'lines'))