Esse trabalho é uma análise gráfica do hiato do produto por meio da aplicação do filtro HP.
seriesbr <- ipeadatar::available_series("br")
PIB <- ipeadata("SCN104_PIBPMAS104")
PIB <- PIB %>%
mutate(quarter = format(date, "%q")) %>%
group_by(date)
PIB <- PIB %>%
summarize(Índice = value)
plot(PIB, type = "l", col = "red")
G1 <- ggplot(data = PIB) +
aes(x = date, y = Índice) +
geom_line(linewidth = 1.1) +
theme(legend.position = "bottom") +
labs(title = "PIB do Brasil",
subtitle = "Preços de mercado, nº índice sazonalmente ajustado (média de 1995 = 100)",
y = "Índice",
x = "Anos",
color = NULL,
caption = "Dados: IBGE/SCN | Elaboração Própria") +
theme_bw() +
theme_economist_white()
G1
log_pib <- log(PIB$Índice)
dados_ts <- ts(data = log_pib, start = c(lubridate::year(min(PIB$date)), lubridate::quarter(min(PIB$date))), frequency = 4)
filtro_ <- hpfilter(x = dados_ts, type = "lambda", freq = 1600)
filtro <- data.frame(data = time(dados_ts), tendencia = exp(fitted(filtro_)))
data_corrigida <- as.Date(as.yearqtr(filtro$data))
cores <- c("PIB" = "darkred",
"Produto Potencial" = "blue")
ggplot() +
geom_line(data = PIB, aes(x = date, y = Índice, color = "PIB"), size = 1) +
geom_line(data = filtro, aes(x = data_corrigida, y = Series.1, color = "Produto Potencial"), size = 1) +
scale_color_manual(values = cores) +
theme(legend.position = "bottom") +
scale_x_date(breaks = seq(min(data_corrigida), max(data_corrigida), by = "4 years"),
labels = scales::date_format("%Y")) +
labs(title = "PIB do Brasil",
subtitle = "Preços de mercado, nº índice sazonalmente ajustado (média de 1995 = 100)",
y = "índice",
x = "Anos",
color = NULL,
caption = "Dados: IBGE/SCN | Elaboração Própria") +
theme_bw() +
theme_economist_white()
hiato <- (PIB$Índice/filtro$Series.1 - 1) * 100
dados <- bind_cols(data_corrigida, hiato)
cores <- c("Hiato" = "darkgreen")
G3 <- ggplot() +
geom_line(data = dados, aes(x = data_corrigida, y = hiato, color = "Hiato"), size = 1.2) +
scale_color_manual(values = cores) +
theme(legend.position = "bottom") +
scale_x_date(breaks = seq(min(data_corrigida), max(data_corrigida), by = "4 years"),
labels = scales::date_format("%Y")) +
geom_hline(yintercept = 0, linetype = "dashed") +
labs(title = "Hiato do Produto",
subtitle = "Aplicação do Filtro HP no PIB a preços de mercado",
y = "%",
x = "Anos",
color = NULL,
caption = "Dados: IBGE/SCN | Elaboração Própria") +
theme_bw() +
theme_economist_white()
G3