Table 1.1.2. Contributions to Percent Change in Real Gross Domestic Product (A) (Q) - T10102

Data - BEA

Layout

  • NIPA Website. html

Ex 2: 1938, 1958, 1978, 1998, 2018 Table

Code
T10102_A |>
  year_to_date() |>
  mutate(year = year(date)) |>
  filter(year %in% c(1938, 1958, 1978, 1998, 2018)) |>
  group_by(year) |>
  mutate(value = round(DataValue, 2)) |>
  ungroup() |>
  select(LineNumber, LineDescription, year, value) |>
  spread(year, value) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

Ex 3: Contributions to GDP Growth

Code
T10102_Q |>
  quarter_to_date() |>
  filter(LineNumber %in% c(2, 7, 15, 22),
         date >= as.Date("1990-01-01")) |>
  mutate(LineDescription = factor(LineDescription,
           levels = c("Personal consumption expenditures",
                      "Gross private domestic investment",
                      "Net exports of goods and services",
                      "Government consumption expenditures and gross investment"),
           labels = c("Consumption", "Investment", "Net exports", "Government"))) |>
  ggplot() + theme_minimal() +
  geom_col(aes(x = date, y = DataValue, fill = LineDescription), width = 80) +
  geom_line(data = T10102_Q |> quarter_to_date() |>
              filter(LineNumber == 1, date >= as.Date("1990-01-01")),
            aes(x = date, y = DataValue), color = "black") +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
  scale_x_date(breaks = seq(1930, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_fill_manual(values = viridis(4)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("Contribution, pp, SAAR (black = GDP growth)") + xlab("")

Ex 4: Contribution of Private Investment

Code
T10102_Q |>
  quarter_to_date() |>
  filter(LineNumber %in% c(8, 14),
         date >= as.Date("1990-01-01")) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = DataValue, color = LineDescription)) +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1990-01-01")),
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
            fill = 'grey', alpha = 0.5) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
  scale_x_date(breaks = seq(1930, 2100, 5) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_color_manual(values = viridis(2)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("Contribution, pp, SAAR") + xlab("")