Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product (A) (Q) - T10101

Data - BEA

Layout

  • NIPA Website. html

Periods

Code
T10101_A |>
  year_to_date() |>
  mutate(year = year(date)) |>
  mutate(period = case_when(year <= 1939 ~ "1930-1939",
                            year <= 1945 ~ "1940-1945",
                            year <= 1975 ~ "1946-1975",
                            year <= 2000 ~ "1976-2000",
                            year <= 2020 ~ "2001-2020")) |>
  select(LineNumber, LineDescription, period, DataValue) |>
  group_by(LineNumber, LineDescription, period) %>%
  summarise(mean_growth = mean(DataValue) |> round(1) |> paste0(" %")) |>
  spread(period, mean_growth) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

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

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

Ex 3: GDP vs Consumption vs Investment Growth

Code
T10101_Q |>
  quarter_to_date() |>
  filter(LineNumber %in% c(1, 2, 7),
         date >= as.Date("1960-01-01")) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = DataValue, color = LineDescription)) +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1960-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, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_color_manual(values = viridis(3)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("% change, SAAR") + xlab("")

Ex 4: Composition of Consumption Growth

Code
T10101_Q |>
  quarter_to_date() |>
  filter(LineNumber %in% c(3, 6),
         date >= as.Date("1960-01-01")) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = DataValue, color = LineDescription)) +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1960-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, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_color_manual(values = viridis(2)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("% change, SAAR") + xlab("")

Ex 5: Composition of Government Spending Growth

Code
T10101_Q |>
  quarter_to_date() |>
  filter(LineNumber %in% c(24, 25, 26),
         date >= as.Date("1960-01-01")) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = DataValue, color = LineDescription)) +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1960-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, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_color_manual(values = viridis(3)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("% change, SAAR") + xlab("")