knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
bartik.weight
The package bartik.weight
is an implementation in R for estimating Rotemberg weights
outlined in Goldsmith-Pinkham, Sorkin and Swift (2018).
The original Stata package by Paul Goldsmith-Pinkham can be found here: https://github.com/paulgp/bartik-weight.
You can install the current version of bartik.weight from Github with:
# install.packages("devtools") devtools::install_github("jjchern/bartik.weight") # To uninstall the package, use: # remove.packages("bartik.weight")
The package includes example datasets:
library(tidyverse) # index: czone, year bartik.weight::ADH_master # index: czone, year, ind bartik.weight::ADH_local # index: year, ind bartik.weight::ADH_global
The main dataset bartik.weight::ADH_master
contains the key variables at the
level of czone-year.
The Bartik instrument is formed by interacting local industry shares (variable
sh_ind_
in the ADH_local
tibble) and the industry growth rates (variable
trade_
in the ADH_global
tibble).
To estimate the Rotemberg weights, it's necessary to transform the local
tibble
from long to wide format:
bartik.weight::ADH_local %>% mutate(ind = str_glue("t{year}_sh_ind_{ind}")) %>% spread(ind, sh_ind_, fill = 0) %>% print() -> ADH_local2
Once all the data is in proper format, the bw()
function will return the weight,
and the just-identified IV estimates:
library(bartik.weight) # Prepare variables in the master tibble y = "d_sh_empl_mfg" x = "d_tradeusch_pw" controls = c("reg_midatl", "reg_encen", "reg_wncen", "reg_satl", "reg_escen", "reg_wscen", "reg_mount", "reg_pacif", "l_sh_popedu_c", "l_sh_popfborn", "l_sh_empl_f", "l_sh_routine33", "l_task_outsource", "t2", "l_shind_manuf_cbp") weight = "timepwt48" # Prepare variables in the local tibble Z = setdiff(names(ADH_local_wide), c("czone", "year")) # Prepare variables in the global tibble G = "trade_" # Estimate the weight (alpha) and the IV estimates (beta) bw = bw(ADH_master, y, x, controls, weight, ADH_local2, Z, ADH_global, G) bw
The following table replicates Panel A of Table 5 in Goldsmith-Pinkham, Sorkin and Swift (2018):
bw %>% mutate(Weight = if_else(alpha > 0, "Positive", "Negative")) %>% group_by(Weight) %>% summarise(Sum = sum(alpha), Mean = mean(alpha)) %>% knitr::kable(digits = 3, caption = "Negative and positive weights")
Below is part of Panel D of Table 5:
bw %>% top_n(5, alpha) %>% arrange(desc(alpha)) %>% mutate(ind = case_when( ind == "3571" ~ "Electronic Computers", ind == "3944" ~ "Games and Toys", ind == "3651" ~ "Household Audio and Video", ind == "3661" ~ "Telephone Apparatus", ind == "3577" ~ "Computer Equipment" )) %>% rename(g = trade_) %>% knitr::kable(digits = 3, caption = "Top five Rotemberg weight industries")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.