An introduction to growth accounting using R
Setup
#install.packages("pwt10")
suppressWarnings(suppressMessages({
#library(pwt9)
library(pwt10)
library(tidyverse)
library(ExPanDaR)
library(plotly)
}))
options(warn = -1, scipen = 10000, repr.plot.width = 6, repr.plot.height = 4)
Production model
Import data
data("pwt10.0")
pwt <- pwt10.0
head(pwt)
Select data
df <- pwt %>%
filter(country %in% c("China", "India", "Japan")) %>%
select(year, isocode, rgdpna, rkna, emp, labsh) %>%
filter(year >= 1980,
year <= 2000) %>%
na.omit()
df
Compute key variables
# Compute log of GDP per worker, log Capital per worker, and capital share
df <- df %>%
mutate(ln_y = log(rgdpna / emp),
ln_k = log(rkna / emp),
alpha = 1 - labsh)
# Order by year (this is very important because we are using a panel data structure)
df <- df %>%
arrange(year)
# For each country calculate growth rates and solow residual
df <- df %>%
group_by(isocode) %>%
mutate(g_y = (ln_y - lag(ln_y)) * 100,
g_k = (ln_k - lag(ln_k)) * 100,
g_A = g_y - alpha * g_k) %>%
na.omit()
df %>%
select(g_A, g_y, g_k, alpha)
Aggregate results
solow <- df %>%
summarise(G_y = mean(g_y),
G_A = mean(g_A),
G_ak = mean(alpha * g_k),
A_share = mean(g_A) / mean(g_y),
ak_share = mean(alpha * g_k) / mean(g_y),
alpha = mean(alpha))
Accounting results
Table
solow
round_df <- function(df, digits) {
nums <- vapply(df, is.numeric, FUN.VALUE = logical(1))
df[,nums] <- round(df[,nums], digits = digits)
(df)
}
round_df(solow, digits=2)
Figures
p <- ggplot(data=solow, aes(x=isocode, y=G_y)) +
geom_bar(stat="identity") +
xlab("") +
ylab("Growth")
ggplotly(p)
solow_long <- solow %>%
select(isocode, G_A, G_ak) %>%
pivot_longer(!isocode, names_to = "Growth", values_to = "Values")
solow_long
p <- ggplot(solow_long, aes(fill=Growth, y=Values, x=isocode)) +
geom_bar(position=position_dodge(), stat="identity") +
xlab("") +
ylab("Growth")
ggplotly(p)
p <- ggplot(solow_long, aes(fill=Growth, y=Values, x=isocode)) +
geom_bar(position="stack", stat="identity") +
xlab("") +
ylab("Growth")
ggplotly(p)
p <- ggplot(solow_long, aes(fill=Growth, y=Values, x=isocode)) +
geom_bar(position="fill", stat="identity") +
xlab("") +
ylab("Growth")
ggplotly(p)