forked from yimengyin16/PenSimMacro_Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data_processRaw_RevGSP.R
129 lines (88 loc) · 3.7 KB
/
Data_processRaw_RevGSP.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Combine data for GSP-tax model
#**********************************************************************
# Notes ####
#**********************************************************************
# Combine data the following data
# 1. Revenue by state from Urban
# 2. GSP 1963-1997 (SIC) and 1997-2016(NAICS) from BEA
#**********************************************************************
# Packages ####
#**********************************************************************
library(tidyverse)
library(readxl)
library(lubridate)
library(xts)
library(zoo)
library(magrittr)
library(stringr)
library(forecast)
# Intro to zoo cran.r-project.org/web/packages/zoo/vignettes/zoo-quickref.pdf
#**********************************************************************
# Global settings ####
#**********************************************************************
dir_data_raw <- "data_raw/"
dir_data_out <- "data_out/"
#**********************************************************************
# Prepare Data ####
#**********************************************************************
# Loading saved data
load(paste0(dir_data_raw, "dataRaw_RevGSP.RData"))
df_GSP_FRED
df_RGSP_BEA
df_NGSP_BEA
Rev_urban_tot_nom
Rev_urban_tot_real
Rev_urban_tot_nom1 <-
Rev_urban_tot_nom %>%
mutate(varname = paste0(varname,"_",nomReal, "_", type)) %>%
select(state_abb, year, varname, value) %>%
spread(varname, value)
Rev_urban_tot_nom1
Rev_urban_tot_real1 <-
Rev_urban_tot_real %>%
mutate(varname = paste0(varname,"_",nomReal, "_", type)) %>%
select(state_abb, year, varname, value) %>%
spread(varname, value)
Rev_urban_tot_real1
df_RevGSP <-
df_RGSP_BEA %>%
left_join(df_NGSP_BEA) %>%
left_join(df_GSP_FRED %>% select(-RGSP)) %>%
left_join(Rev_urban_tot_nom1) %>%
left_join(Rev_urban_tot_real1)
df_RevGSP
#**********************************************************************
# Notes for df_RevGSP ####
#**********************************************************************
# Variables
# Indices: state, state_abb, year
# GSP variables
# - RGSP_SIC: From BEA, 1963-1997, based on SIC
# - RGSP_NAICS: From BEA, 1997-2016, based on NAICS
# - NGSP: From FRED, 1997-2016
# Tax and revenue variables: 1977-2015
# - suffix:
# - local
# - state
# - SL: state and local
# - variables:
# urban code Var name Var description
# 'R01', 'rev_tot', 'Total revenue',
# 'R02', 'rev_tot_ownSrc', 'Total Rev-Own Sources',
# 'R03', 'rev_gen', 'General Revenue',
# 'R04', 'rev_gen_ownSrc', 'Gen Rev-Own Sources',
# 'R05', 'tax_tot', 'Total Taxes',
# 'R06', 'tax_property', 'Property Taxes',
# 'R08', 'tax_sales_tot', 'Tot Sales & Gr Rec Tax',
# 'R09', 'tax_sales_gen', 'Total Gen Sales Tax (T09)',
# 'R10', 'tax_sales_select', 'Total select Sales Tax',
# 'R27', 'tax_indivIncome', 'Individual Income Tax (T40)',
# 'R28', 'tax_corpIncome', 'Corp Net Income Tax',
# 'R36', 'chgs_Misc', 'Tot Chgs and Misc Rev'
# - with missing values
#**********************************************************************
# Saving Data ####
#**********************************************************************
save(df_RevGSP,
df_us_states,
file = paste0(dir_data_out, "Data_RevGSP.RData"))