Brazilian GDP 2020:Q2

Data from the 2020:Q2 Brazilian GDP

Paulo Ferreira Naibert https://github.com/pfnaibert/
2020-09-01

In this post, we will do a not so deep dive in the IBGE release of the 2020:Q2 GDP results. As usual, my source code for the functions can be found here.

First, let’s load up our functions and other libraries.


# source functions
source("../../R/funs-macro.R")

# load libraries
library(reshape2)
library(ggplot2)
library(dygraphs)

I already downloaded the data from the SIDRA website using the functions, from the funs-macro.R file.


gdp.dl()
gdp.save.rets()
gdp.save.levels()

Now, we load the data and make some transformations.


# LOAD DATA

# levels
gdp.nominal <- readRDS("../../data/gdp-nominal.rds")
gdp.index   <- readRDS("../../data/gdp-index-NSA.rds")
gdp.real    <- readRDS("../../data/gdp-real-NSA.rds")

# rets
gdp.ret4    <- readRDS("../../data/gdp-ret4.rds")
gdp.ret1    <- readRDS("../../data/gdp-ret1.rds")
gdp.retsum4 <- readRDS("../../data/gdp-retsum4.rds")
gdp.retyear <- readRDS("../../data/gdp-retyear.rds")

# data as ts (for dygraphs)
gdp.nominal.ts <- df2ts(gdp.nominal)
gdp.index.ts   <- df2ts(gdp.index)
gdp.real.ts    <- df2ts(gdp.real)
gdp.ret4.ts    <- df2ts(gdp.ret4)
gdp.ret1.ts    <- df2ts(gdp.ret1)
gdp.retsum4.ts <- df2ts(gdp.retsum4)
gdp.retyear.ts <- df2ts(gdp.retyear)

# only GDPs
gdps <- data.frame( gdp.nominal[, c(1,2,3)],  "nominal"=gdp.nominal[, "GDP"]/1000, "index"=gdp.index[, "GDP"], "real"=gdp.real[, "GDP"]/1000 )
gdps$nominal.sum4 <- sum4(gdps$nominal)
gdps$real.sum4    <- sum4(gdps$real)
gdps$index.sum4   <- sum4(gdps$index)/4
gdps.ts <- df2ts(gdps)

GGPLOT Functions

Because I will make a lot of the same plot, but using different data as input, I decided to make some ggplot wraper functions.


# function to ggplot Growth by SECTORS
ggplot.last <- function(data, vars)
{
# TODO: ERROR CATCHING

newdata <- melt( sort( tail( data[, vars], 1 ), decreasing=T ) )

# plot
ggplot(newdata, aes( x = variable, y = value, fill = value > 0 ) ) +
geom_bar( stat="identity" ) +
scale_fill_manual(values=c("red", "blue") ) +
guides(fill=FALSE) +
geom_hline(yintercept=0 ) +
geom_text( aes(label=value, vjust=ifelse(value > 0, "bottom", "top") ) )+
theme(axis.text.x = element_text(color="black", size=10, angle=90) ) +
xlab("") + ylab("")
}

# function to ggplot Growth by SECTORS
ggplot.growth <- function(data, ndates, vars)
{
# TODO: ERROR CATCHING

newdata      <- tail(data[, vars], ndates)
newdata$date <- date2qtr( newdata$date )
newdata      <- melt( newdata, id="date" )

#plot
ggplot(newdata, aes( x = date, y = value, group=variable, color=variable) ) +
geom_line( size=1 ) +
geom_hline(yintercept=0 ) +
theme(axis.text.x = element_text(color="black", size=11) ) +
xlab("") + ylab("")
}

# vars for ggplot.last
cond.vars <- !(colnames(gdp.ret4) %in% c("date", "year", "qtr", "IND", "SER", "VAB", "TAX", "C", "FBKF", "M", "X", "G"))
vars1     <- colnames(gdp.ret4[, cond.vars])

GDP GROWTH

T/T-1 (With Seasonal Adjustment)


ggplot.last(gdp.ret1, vars1)


ggplot.growth(gdp.ret1, ndates=8, vars=c("date", "GDP", "AGR", "IND", "SER"))


dygraph(window(gdp.ret1.ts[,c("GDP", "AGR", "IND", "SER")], start=c(2018,3) ), main = "GDP by Sectors") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(0))

ggplot.growth(gdp.ret1, ndates=8, vars=c("date", "GDP", "C", "G", "FBKF", "X", "M"))


dygraph(window(gdp.ret1.ts[,c("GDP", "C", "G", "FBKF", "X", "M")], start=c(2018,3) ), main = "GDP by Demand Variables") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(0))

T/T-4


ggplot.last(gdp.ret4, vars1)


ggplot.growth(gdp.ret4, ndate=8, vars=c("date", "GDP", "AGR", "IND", "SER", "TAX"))


dygraph(window(gdp.ret4.ts[,c("GDP", "AGR", "IND", "SER", "TAX")], start=c(2018,3) ), main = "GDP by Sectors") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(0))

ggplot.growth(gdp.ret4, ndate=8, vars=c("date", "GDP", "C", "G", "FBKF", "X", "M"))


dygraph(window(gdp.ret4.ts[,c("GDP", "C", "G", "FBKF", "X", "M")], start=c(2018,3) ), main = "GDP by Demand Variables") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(0))

AC4Q T/T-4


ggplot.last(gdp.retsum4, vars1)


ggplot.growth(gdp.retsum4, ndate=8, vars=c("date", "GDP", "AGR", "IND", "SER", "TAX"))


dygraph(window(gdp.retsum4.ts[,c("GDP", "AGR", "IND", "SER", "TAX")], start=c(2018,3) ), main = "GDP by Sectors") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(0))

ggplot.growth(gdp.retsum4, ndate=8, vars=c("date", "GDP", "C", "G", "FBKF", "X", "M"))


dygraph(window(gdp.retsum4.ts[,c("GDP", "C", "G", "FBKF", "X", "M")], start=c(2018,3) ), main = "GDP by Demand Variables") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(0))

GDP GROWTH TABLES

T/T-1 (With Seasonal Adjustment)


paged_table(gdp.table(gdp.ret1, type="ret1", digits=1 ), list(rows.print=12) )

T/T-4


paged_table(gdp.table(gdp.ret4, type="ret4", digits=1), list(rows.print=12) )

AC4Q T/T-4


paged_table(gdp.table(gdp.retsum4, type="ret4", digits=1), list(rows.print=12) )

GDP LEVELS

NOMINAL


dygraph(gdps.ts[,"nominal"], main = "Nominal GDP (Billions of Current BRL)") %>%
dySeries(label = "Nominal GDP") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(gdps.ts[NROW(gdps), "nominal"]) )

dygraph(gdps.ts[,"nominal.sum4"], main = "Nominal GDP AC4Q (Billions of Current BRL)") %>%
dySeries(label = "Nominal GDP") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(gdps.ts[NROW(gdps), "nominal.sum4"]) )

REAL


dygraph(gdps.ts[,"index"], main = "GDP INDEX (1995=100)") %>%
dySeries(label = "GDP") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(gdps.ts[NROW(gdps), "index"]) )

dygraph(gdps.ts[,"index.sum4"], main = "GDP INDEX Mean of 4 Quarters (1995=100)") %>%
dySeries(label = "GDP") %>%
dyAxis("x", rangePad = 10, drawGrid = FALSE) %>%
dyLimit( as.numeric(gdps.ts[NROW(gdps), "index.sum4"]) )

GDP LEVELS TABLES

NOMINAL (Millions of Current BRL)


paged_table( gdp.table(gdp.nominal, type="level" , period="qtr", digits=0), list(rows.print=12) )

SIDRA TABLE

REAL (Milliions of 1995 Chained BRL)


paged_table( gdp.table(gdp.real, type="ret4" , period="qtr", digits=0), list(rows.print=12) )

SIDRA TABLE

INDEX (Chained Index)


paged_table( gdp.table(gdp.index, type="ret4" , period="qtr", digits=2), list(rows.print=12) )

SIDRA TABLE

NEXT RELEASES FROM IBGE

Reference Date Publishing Date
2020:Q3 2020-12-03

THANK YOU FOR READING!

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.