From 6c79431506114d3f3cb55a873399df018513c723 Mon Sep 17 00:00:00 2001 From: "Matthew E. Dardet" <42788276+matthewdardet@users.noreply.github.com> Date: Fri, 3 Dec 2021 10:34:44 -0500 Subject: [PATCH] Modifications to make code run. --- rCode/fipsCodeLabel.R | 4 ++-- rCode/main.R | 12 ++++++------ rCode/natlCalcs.R | 2 +- rCode/preamble.R | 14 ++++++++++++++ rCode/replicateBartikInstrument.R | 4 ++-- rCode/replicateRegsAndExtend_short v2.R | 5 +++-- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/rCode/fipsCodeLabel.R b/rCode/fipsCodeLabel.R index c707364..346f2be 100644 --- a/rCode/fipsCodeLabel.R +++ b/rCode/fipsCodeLabel.R @@ -8,7 +8,7 @@ # maybe they omit bedford city because their list is post 2013 -countyLevelRaw <- read_dta("OriginalMaterials/county_level.dta") +countyLevelRaw <- read_dta(here::here("OriginalMaterials/county_level.dta")) allFIPS <- tidycensus::fips_codes %>% tibble() %>% @@ -41,7 +41,7 @@ countyLevel <- countyLevel0 %>% left_join(allFIPSBW %>% dplyr::select(id, coun # these are missing in BW as well -saveRDS(countyLevel, "data/BWCountyLevel.rds") +saveRDS(countyLevel, here::here("data/BWCountyLevel.rds")) diff --git a/rCode/main.R b/rCode/main.R index 1042beb..2c375fe 100644 --- a/rCode/main.R +++ b/rCode/main.R @@ -1,5 +1,5 @@ # load packages -source("rCode/preamble.R") +source("preamble.R") # Global vars ######################################################## @@ -16,15 +16,15 @@ QWIName <- "timeseries/qwi/rh" # Pull census data if it doesn't exist ######################################################## -if(!file.exists("data/censusDataByCounty.rds")){ source("rCode/censusAPIPull.R") } +if(!file.exists("data/censusDataByCounty.rds")){ source("censusAPIPull.R") } # clean up BW data if not done - add FIPS code guesses etc if(!file.exists("data/BWCountyLevel.rds")){ source("rCode/fipsCodeLabel.R")} -BWDataByCounty <- readRDS("data/BWCountyLevel.rds") +BWDataByCounty <- readRDS(here::here("data/BWCountyLevel.rds")) # national aggregates for employment -if(!file.exists("data/natlResult.rds")){ source("rCode/natlCalcs.R")} -natlResult <- readRDS("data/natlResult.rds") +if(!file.exists("data/natlResult.rds")){ source("natlCalcs.R")} +natlResult <- readRDS(here::here("data/natlResult.rds")) # create our own bartik instrument -if(!file.exists("data/finalBartik.RDS")){ source("rCode/replicateBartikInstrument.R")} +if(!file.exists("data/finalBartik.RDS")){ source("replicateBartikInstrument.R")} bartikOurs <- readRDS("data/finalBartik.RDS") ######################################################## \ No newline at end of file diff --git a/rCode/natlCalcs.R b/rCode/natlCalcs.R index 60fe2f2..d9f41c6 100644 --- a/rCode/natlCalcs.R +++ b/rCode/natlCalcs.R @@ -73,7 +73,7 @@ saveRDS(list( whiteEmpl = whiteEmpl$whiteEmp, nonwhiteLayoffs = nonwhiteLayoffs$nonwhiteLayoffs, nonwhiteNetChange = nonwhiteNetChange$nonwhiteNetChange, - nonwhiteEmpl = nonwhiteEmpl$nonwhiteEmp), "data/natlResult.rds") + nonwhiteEmpl = nonwhiteEmpl$nonwhiteEmp), here::here("data/natlResult.rds")) diff --git a/rCode/preamble.R b/rCode/preamble.R index a861d2a..5a1dc0d 100644 --- a/rCode/preamble.R +++ b/rCode/preamble.R @@ -1,3 +1,15 @@ +packages <- c("censusapi", "tidycensus", + "tidyverse", "stringr", + "xlsx", "assertthat", + "tictoc", "haven", + "stargazer", "AER", + "lfe", "lmtest", + "CBPS", "here") + +if(length(which(!packages %in% installed.packages())) > 0) { + install.packages(packages[!packages %in% installed.packages()]) +} + library(censusapi) library(tidycensus) library(tidyverse) @@ -11,6 +23,8 @@ library(AER) library(lfe) library(lmtest) library(CBPS) +library(here) + diff --git a/rCode/replicateBartikInstrument.R b/rCode/replicateBartikInstrument.R index 3f488a3..7e01fb0 100644 --- a/rCode/replicateBartikInstrument.R +++ b/rCode/replicateBartikInstrument.R @@ -1,7 +1,7 @@ ################################################################ -countyLevelData <- readRDS("data/censusDataByCounty.rds") -natlResult <- readRDS("data/natlResult.rds") +countyLevelData <- readRDS(here::here("data/censusDataByCounty.rds")) +natlResult <- readRDS(here::here("data/natlResult.rds")) ################################################################ aggregate <- totalData %>% left_join(mfgData) %>% diff --git a/rCode/replicateRegsAndExtend_short v2.R b/rCode/replicateRegsAndExtend_short v2.R index 7e24e26..6409ea2 100644 --- a/rCode/replicateRegsAndExtend_short v2.R +++ b/rCode/replicateRegsAndExtend_short v2.R @@ -1,7 +1,7 @@ -source("rCode/preamble.R") -BWDataByCounty <- readRDS("data/BWCountyLevel.rds") +source("preamble.R") +BWDataByCounty <- readRDS(here::here("data/BWCountyLevel.rds")) ################################################################################# # First we run our code with their data to replicate @@ -524,3 +524,4 @@ saveRDS(list( secondStageModelNetC04 = secondStageModelOurs04_3, secondStageModelWNetC04 = secondStageModelOurs04_6), file = "regresults.rds") +