-
Notifications
You must be signed in to change notification settings - Fork 3
/
GovFin_modeling(9).R
2598 lines (2027 loc) · 97 KB
/
GovFin_modeling(9).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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This script explore the relationship between GSP and state gov revenue and does exploratory modeling
# It is also for the first draft of the policy brief.
#**********************************************************************
# Notes ####
#**********************************************************************
# To-do list for GSP and tax revenue section
# What to model:
# 1. Personal income tax: relationship with GSP growth and returns (stock and/or portfolio)
# 2. General Sales tax: relationship with GSP, how the relationship changes during recessions
# 3. Other taxes (non-PIT-non-sales taxes): relationship with GSP
# 4. Construct stylized government types
# Notes on inflation adustment
# - Use national level GDP price index or GDP deflator to recalculate real tax revenue.
# a. The real tax revenue data from Urban are calculated using CPI-U,
# which is not consistent with the inflation adjustment method for GDP (by chain-type indices)
# b. GDP price index may work better than CPI-U for our purpose. (the basket of goods is fixed in CPI, but changes over time in GDP price index)
# - Use real values for now. When integrated with macro model, which uses real GDP,
# add the assumed inflation rate to the GSP growth rate. So we do not model inflation
# in this version.
# Notes on data
# 1. National GDP from FRED, 2nd quarter data for annual data. This may be more consistent with the timing of FY for most states
# Notes on decomposing GDP and tax revenue
# Other relationships to examine:
# 1. GSP growth and total own soure revenue growth,
# 2. GSP growth and total tax revenue growth
# 3. GSP growth and personal income tax growth
# 4. GSP growth and sales tax growth
# 5. GSP growth and property tax growth
# 6. GSP growth and corporate income tax growth
# 7. GSP growth and growth of total tax revenue minus PIT and sales
# 8. national GDP growth and GSP growth
# Notes on real and nominal variables
# - results for nominal variables for 1995-2015 can be compared with Pew results
# - GDP/GSP are modeled in real terms in the macro model, so the GDP-revenue relationship should be
# modeld using real term. But note that pension contributions are modeled in nominal terms, which
# must be compared against nominal gov revenue.
# - Real revenue variables are in 2015 dollar and adjustment factor for inflation is the same across
# all states, gov levels and types of tax, while real GSPs are in 2009 dollar and adjustment factors
# for inflation differ across states.
# How sales taxes are divided between state and local governments:
# https://taxfoundation.org/state-and-local-sales-tax-rates-in-2017/
# Five states do not have statewide sales taxes: Alaska, Delaware, Montana, New Hampshire, and Oregon.
# Of these, Alaska and Montana allow localities to charge local sales taxes.
#**********************************************************************
# Packages ####
#**********************************************************************
library(tidyverse)
library(broom)
library(readxl)
library(magrittr)
library(ggrepel)
library(stringr)
library(forcats)
library(grid)
library(gridExtra)
library(scales)
library(knitr)
library(xlsx)
# packages for econometric and time series modeling
library(plm)
library(astsa) # companion package
library(TSA) # companion package; arimax: flexible transfer function model
library(tseries) #
library(forecast) # Arima
library(MSwM)
library(TTR)
library(dynlm)
library(broom)
library(mFilter) # HP filter "hpfilter"
#library(MSBVAR)
# packages for ts
library(zoo)
library(xts)
library(timetk)
library(tidyquant)
library(lubridate)
library(feather)
library(psych) # describe
options(tibble.print_max = 60, tibble.print_min = 60)
# check tidyquant, timetk, sweep (broom ), tibbletime
# Intro to zoo cran.r-project.org/web/packages/zoo/vignettes/zoo-quickref.pdf
# sweep: http://www.business-science.io/code-tools/2017/07/09/sweep-0-1-0.html
#**********************************************************************
# Global settings and tools ####
#**********************************************************************
dir_data_raw <- "data_raw/"
dir_data_out <- "data_out/"
dir_fig_out <- "outputs_report/"
# NBER recession periods, post-WWII
recessionPeriods <-
matrix(c(
1953+2/4, 1954+2/4,
1957+3/4, 1958+2/4,
1960+2/4, 1961+1/4,
1969+4/4, 1970+4/4,
1973+4/4, 1975+1/4,
1980+1/4, 1980+3/4,
1981+3/4, 1982+4/4,
1990+3/4, 1991+1/4,
2001+1/4, 2001+4/4,
2007+4/4, 2009+2/4
) , ncol = 2, byrow = T) %>%
as.data.frame() %>%
rename(peak = V1,
trough = V2) %>%
mutate(peak = peak - 1/4,
trough = trough - 0/4)
get_logReturn <- function(x){
if(any(x <= 0, na.rm = TRUE)) stop("Nagative value(s)")
log(x/lag(x))
}
# RIG colors and theme
RIG.blue <- "#003598"
RIG.red <- "#A50021"
RIG.green <- "#009900"
RIG.yellow <- "#FFFF66"
RIG.purple <- "#9966FF"
RIG.yellow.dark <- "#ffc829"
RIG.orange <- "#fc9272"
demo.color6 <- c(RIG.red,
RIG.orange,
RIG.purple,
RIG.green ,
RIG.blue,
RIG.yellow.dark)
RIG.theme <- function() {
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line(size = 0.5, color = "gray80"),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
plot.caption = element_text(hjust = 0, size = 9)
)
}
RIG.themeLite <- function() {
theme(
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
plot.caption = element_text(hjust = 0, size = 9)
)
}
color_PIT <- RIG.green
color_salesgen <- "blue"
color_salessel <- "deepskyblue2"
color_other <- RIG.purple
color_propertyLoc <- RIG.yellow.dark
color_GDP <- "gray50"
#**********************************************************************
# Data preparation 1: tax revenue and GSP ####
#**********************************************************************
# 1. Loading saved data
load(paste0(dir_data_out, "data_RevGSP.RData"))
load(paste0(dir_data_out, "dataAll.RData"))
# Variables in df_RevGSP
# Indices: state, state_abb, year
# GSP variables (calendar year)
# - RGSP_SIC: From BEA, 1987-1997, based on SIC
# - RGSP_NAICS: From BEA, 1997-2016, based on NAICS
# - NGSP_SIC: From BEA, 1963-1997, based on SIC
# - NGSP_NAICS: From BEA, 1997-2016, based on NAICS
# - NGSP: From FRED, 1997-2016 (no national level)
# Tax and revenue variables: 1977-2015 (Fiscal year)
# - suffix for gov levels:
# - local
# - state
# - SL: state and local
# - suffix for real or nominal: real / nom
#
# - 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
# 2. Produce real tax revenue by applying GDP price index
# Notes: GDP price deflator and GDP chain-type price index are very close.
# For now, we stick with GDP chain-type price index
# df_dataAll_y %>%
# select(year, GDPdeflator_FRED, GDPCTPI_FRED) %>%
# mutate_at(vars(-year), funs(100 * log(./lag(.)))) %>%
# mutate(diff = GDPdeflator_FRED - GDPCTPI_FRED)
df_RevGDP_GDPCTPI <-
df_RevGSP %>% select(state_abb, year, NGSP_SIC,NGSP_NAICS, contains("_nom_")) %>%
left_join(df_dataAll_y %>% select(year, GDPCTPI_FRED)) %>%
mutate_at(vars(-year, -state_abb), funs(./(GDPCTPI_FRED/100))) %>%
rename_all(funs(str_replace(., "_nom_", "_real2_"))) %>%
rename_all(funs(str_replace(., "NGSP", "RGSP2")))
# 3. Real terms based on CPI-U (Urban's calculation BEA real GSP starts from 1987)
df_real <-
df_RevGSP %>%
select(state_abb, year,
RGSP_SIC, RGSP_NAICS,
tax_tot_real_state,
tax_indivIncome_real_state,
tax_sales_tot_real_state,
tax_sales_gen_real_state,
tax_sales_select_real_state,
tax_corpIncome_real_state,
tax_property_real_state,
tax_property_real_local) %>%
mutate(tax_other_real_state = tax_tot_real_state - tax_indivIncome_real_state -
tax_sales_tot_real_state - tax_corpIncome_real_state - tax_property_real_state,
tax_nonPITsalesgen_real_state = tax_tot_real_state - tax_indivIncome_real_state - tax_sales_gen_real_state,
tax_nonPITsalestot_real_state = tax_tot_real_state - tax_indivIncome_real_state - tax_sales_tot_real_state,
RGSPc = ifelse(year >= 1997, RGSP_NAICS, RGSP_SIC),
#RGSPc = 1000 * RGSPc,
PIT_tax_real = 100 * tax_indivIncome_real_state/tax_tot_real_state,
tax_GSP_real = 100 * tax_tot_real_state / RGSPc)
df_dlreal <-
df_real %>%
group_by(state_abb) %>%
mutate_at(vars(-year), funs(log(./lag(.)))) %>%
mutate(RGSP = ifelse(year > 1997, RGSP_NAICS, RGSP_SIC)) %>%
ungroup() %>%
rename_at(vars(-year, -state_abb), funs(paste0("dl", .) ))
df_real
df_dlreal
# 4. Real terms based on GDP price index (SIC from 1963-1997, NAICS from 1997-2016)
df_real2 <-
df_RevGDP_GDPCTPI %>%
select(state_abb, year,
RGSP2_SIC, RGSP2_NAICS,
tax_tot_real2_state,
tax_indivIncome_real2_state,
tax_sales_tot_real2_state,
tax_sales_gen_real2_state,
tax_sales_select_real2_state,
tax_corpIncome_real2_state,
tax_property_real2_state,
tax_property_real2_local) %>%
mutate(tax_other_real2_state = tax_tot_real2_state - tax_indivIncome_real2_state -
tax_sales_tot_real2_state - tax_corpIncome_real2_state - tax_property_real2_state,
tax_nonPITsalesgen_real2_state = tax_tot_real2_state - tax_indivIncome_real2_state - tax_sales_gen_real2_state,
tax_nonPITsalestot_real2_state = tax_tot_real2_state - tax_indivIncome_real2_state - tax_sales_tot_real2_state,
RGSP2c = ifelse(year >= 1997, RGSP2_NAICS, RGSP2_SIC),
#RGSP2c = 1000 * RGSP2c,
PIT_tax_real2 = 100 * tax_indivIncome_real2_state/tax_tot_real2_state,
tax_GSP_real2 = 100 * tax_tot_real2_state / RGSP2c)
df_dlreal2 <-
df_real2 %>%
group_by(state_abb) %>%
mutate_at(vars(-year), funs(log(./lag(.)))) %>%
mutate(RGSP = ifelse(year > 1997, RGSP2_NAICS, RGSP2_SIC)) %>%
ungroup() %>%
rename_at(vars(-year, -state_abb), funs(paste0("dl", .) ))
df_real2
df_dlreal2
# Nominal terms (BEA nominal GSP starts from 1963)
df_nom <-
df_RevGSP %>%
select(state_abb, year,
NGSP_SIC, NGSP_NAICS,
tax_tot_nom_state,
tax_indivIncome_nom_state,
tax_sales_tot_nom_state,
tax_sales_gen_nom_state,
tax_sales_select_nom_state,
tax_corpIncome_nom_state,
tax_property_nom_state,
tax_property_nom_local) %>%
mutate(tax_other_nom_state = tax_tot_nom_state - tax_indivIncome_nom_state -
tax_sales_tot_nom_state - tax_corpIncome_nom_state - tax_property_nom_state,
tax_nonPITsalesgen_nom_state = tax_tot_nom_state - tax_indivIncome_nom_state - tax_sales_gen_nom_state,
tax_nonPITsalestot_nom_state = tax_tot_nom_state - tax_indivIncome_nom_state - tax_sales_tot_nom_state,
NGSPc = ifelse(year > 1997, NGSP_NAICS, NGSP_SIC),
# NGSPc = 1000 * NGSPc,
PIT_tax_nom = 100 * tax_indivIncome_nom_state/tax_tot_nom_state,
tax_GSP_nom = 100 * tax_tot_nom_state / NGSPc)
df_dlnom <-
df_nom %>%
group_by(state_abb) %>%
mutate_at(vars(-year), funs(log(./lag(.)))) %>%
mutate(NGSP = ifelse(year > 1997, NGSP_NAICS, NGSP_SIC)) %>%
ungroup() %>%
rename_at(vars(-year, -state_abb), funs(paste0("dl", .)))
df_nom
df_dlnom
#**********************************************************************
# Data preparation 2: Asset returns ####
#**********************************************************************
# GSP and real tax revenue data
# Notes:
# GSP from 1988-2016
# tax from 1978-2015
# Common period:1988-2015
# Nominal GSP goes back to 1964, may want to extend the real GSP series by adjusting pre-1988 nominal GSP for inflation
# df_dlRevGSP_reg <-
# df_dlreal %>%
# select(state_abb, year,
# RGSP,
# tax_tot_real_state,
# tax_indivIncome_real_state,
# tax_sales_gen_real_state,
# tax_sales_select_real_state,
# tax_sales_tot_real_state,
# tax_corpIncome_real_state,
# tax_property_real_state,
# tax_other_real_state,
# tax_nonPITsalestot_real_state) %>%
# filter(year %in% 1978:2015, state_abb %in% df_us_states$state_abb) %>%
# mutate_at(vars(-year), funs(./100))
# df_dlRevGSP_reg
# 1. Asset index data from SBBI and national GDP from FRED (check it against the aggregate GSP for all states)
df_SBBI <-
df_dataAll_y %>%
select(year, month, yearMon,
GDP_FRED, # National GDP from FRED, in billions
CPIU_NA_FRED, # CPI, urban resident, not seasonally adjusted. FRED
GDPCTPI_FRED, # GDP chain-type price index
Inflation_Index, # SBBI, inflation index
LCapStock_TRI, # SBBI, large cap stock total return index (SP500 total return index)
LCapStock_CAI, # SBBI, large cap stock capital appreciation index (SP500 price index)
CBond_TRI, # SBBI, corp bond total return
LTGBond_TRI, # SBBI, long-term gov bond total return (20y?)
MTGBond_TRI, # SBBI, medium-term gov bond total return
LTGBond_Yield # SBBI, long-term gov bond yield
) %>%
mutate(GDP_FRED = GDP_FRED * 1e6) %>% # unit from $billion to $thousand, (tax revenues are in $thousand)
filter(year %in% 1977:2015)
# 1.1 Compute asset return and GDP growth (FRED) from indexes
df_dlSBBI <- df_SBBI %>%
mutate_at(vars(-year, -month, -yearMon, -LTGBond_Yield), funs(log(./lag(.)))) %>%
rename_at(vars(-year, -month, -yearMon, -LTGBond_Yield), funs(paste0("dl", .)) )
# 2. Asset return data from NYU Stern
df_assetReturn_nyu <- read_excel(paste0(dir_data_raw, "/histretSP_201801.xls"), sheet = "Returns by year", skip = 17)[,1:4]
names(df_assetReturn_nyu) <- c("year", "SP500_return_nyu", "TBill_return_nyu", "TBond_return_nyu")
df_assetReturn_nyu %<>% mutate(year = as.numeric(year)) %>% filter(year <= 2017)
df_assetReturn_nyu
# 3. Captial gain / losses data for states (From Don)
# level in $billions
rlzCapGains_nom <- read_excel(paste0(dir_data_raw, "/NationalCapitalGains_yy.xlsx"), sheet = "CapGains", range = c("A5:C67"))
names(rlzCapGains_nom) <- c("year", "capgains", "capgains_chg")
rlzCapGains_nom %<>% mutate(capgains = capgains * 1e6)
rlzCapGains_nom_rev <- read_excel(paste0(dir_data_raw, "/NationalCapitalGains_yy.xlsx"), sheet = "CapGains_rev", range = c("A8:E30"))[,-(2:3)]
rlzCapGains_nom_rev
# 4. combine data
# Notes: 1977 to 2015, except for tax_gain and tax_gain_chg
df_returns <-
df_SBBI %>%
left_join(df_dlSBBI) %>%
left_join(df_assetReturn_nyu) %>%
left_join(rlzCapGains_nom) %>%
left_join(rlzCapGains_nom_rev)
## 5. getting real variables
df_returns %<>%
mutate(# real changes based on CPI
dlLCapStock_TRI_real = dlLCapStock_TRI - dlInflation_Index,
dlLCapStock_CAI_real = dlLCapStock_CAI - dlInflation_Index,
dlCBond_TRI_real = dlCBond_TRI - dlInflation_Index,
dlLTGBond_TRI_real = dlLTGBond_TRI - dlInflation_Index,
dlMTGBond_TRI_real = dlMTGBond_TRI - dlInflation_Index,
SP500_return_nyu_real = SP500_return_nyu - dlInflation_Index,
TBill_return_nyu_real = TBill_return_nyu - dlInflation_Index,
TBond_return_nyu_real = TBond_return_nyu - dlInflation_Index,
capgains_chg_real = capgains_chg - dlInflation_Index,
tax_gains_chg_real = tax_gains_chg - dlInflation_Index,
# real changes based on GDP price index
dlLCapStock_TRI_real2 = dlLCapStock_TRI - dlGDPCTPI_FRED,
dlLCapStock_CAI_real2 = dlLCapStock_CAI - dlGDPCTPI_FRED,
dlCBond_TRI_real2 = dlCBond_TRI - dlGDPCTPI_FRED,
dlLTGBond_TRI_real2 = dlLTGBond_TRI - dlGDPCTPI_FRED,
dlMTGBond_TRI_real2 = dlMTGBond_TRI - dlGDPCTPI_FRED,
SP500_return_nyu_real2 = SP500_return_nyu - dlGDPCTPI_FRED,
TBill_return_nyu_real2 = TBill_return_nyu - dlGDPCTPI_FRED,
TBond_return_nyu_real2 = TBond_return_nyu - dlGDPCTPI_FRED,
capgains_chg_real2 = capgains_chg - dlGDPCTPI_FRED,
tax_gains_chg_real2 = tax_gains_chg - dlGDPCTPI_FRED,
# real index/amount based on CPI
LCapStock_TRI_real = LCapStock_TRI / (Inflation_Index/Inflation_Index[year == 2009]),
LCapStock_CAI_real = LCapStock_CAI / (Inflation_Index/Inflation_Index[year == 2009]),
CBond_TRI_real = CBond_TRI / (Inflation_Index/Inflation_Index[year == 2009]),
LTGBond_TRI_real = LTGBond_TRI / (Inflation_Index/Inflation_Index[year == 2009]),
MTGBond_TRI_real = MTGBond_TRI / (Inflation_Index/Inflation_Index[year == 2009]),
capgains_real = capgains / (Inflation_Index/Inflation_Index[year == 2009]),
tax_gains_real = tax_gains / (Inflation_Index/Inflation_Index[year == 2009]),
# real index/amount based on GDP price index
LCapStock_TRI_real2 = LCapStock_TRI /(GDPCTPI_FRED/100),
LCapStock_CAI_real2 = LCapStock_CAI /(GDPCTPI_FRED/100),
CBond_TRI_real2 = CBond_TRI /(GDPCTPI_FRED/100),
LTGBond_TRI_real2 = LTGBond_TRI /(GDPCTPI_FRED/100),
MTGBond_TRI_real2 = MTGBond_TRI /(GDPCTPI_FRED/100),
capgains_real2 = capgains /(GDPCTPI_FRED/100),
tax_gains_real2 = tax_gains /(GDPCTPI_FRED/100)
) %>%
ungroup
#**********************************************************************
# Data preparation 3: Combine data ####
#**********************************************************************
df_real %<>% left_join(df_returns)
df_dlreal %<>% left_join(df_returns)
df_real2 %<>% left_join(df_returns)
df_dlreal2 %<>% left_join(df_returns)
df_nom %<>% left_join(df_returns)
df_dlnom %<>% left_join(df_returns)
#**********************************************************************
# Regression analysis: decomposition of GDP and tax revenue ####
#**********************************************************************
# Variables to decompose (national)
# Tax in real terms (GDP price index)
# PIT, state
# general sales, state
# selective sales, state
# non-PIT-non-sales, state
# Property, local
# National GDP (FRED)
# Real total stock return (LCapStock_TRI)
# capital gains
df_decomp_real2 <-
df_real2 %>%
filter(state_abb == "US", year %in% 1977:2015) %>%
select(year, state_abb, year,
tax_indivIncome_real2_state,
tax_sales_gen_real2_state,
tax_sales_tot_real2_state,
tax_sales_select_real2_state,
tax_nonPITsalestot_real2_state,
tax_property_real2_local,
GDP_FRED,
RGSP2c,
LCapStock_TRI_real2,
capgains_real2
) %>%
mutate(
GDP_log = log(GDP_FRED),
GDP_logtrend = hpfilter(GDP_log, freq = 100)$trend,
GDP_logcycle = hpfilter(GDP_log, freq = 100)$cycle,
GDP_dlog = GDP_log - lag(GDP_log),
GDP_dlogtrend= GDP_logtrend - lag(GDP_logtrend),
GDP_dlogcycle = GDP_logcycle - lag(GDP_logcycle),
# GDP_cycle_fct = exp(GDP_logcycle),
PIT_log = log(tax_indivIncome_real2_state),
PIT_logtrend = hpfilter(PIT_log, freq = 100)$trend,
PIT_logcycle = hpfilter(PIT_log, freq = 100)$cycle,
PIT_dlog = PIT_log - lag(PIT_log),
PIT_dlogtrend= PIT_logtrend - lag(PIT_logtrend),
PIT_dlogcycle = PIT_logcycle - lag(PIT_logcycle),
salesgen_log = log(tax_sales_gen_real2_state),
salesgen_logtrend = hpfilter(salesgen_log, freq = 100)$trend,
salesgen_logcycle = hpfilter(salesgen_log, freq = 100)$cycle,
salesgen_dlog = salesgen_log - lag(salesgen_log),
salesgen_dlogtrend= salesgen_logtrend - lag(salesgen_logtrend),
salesgen_dlogcycle = salesgen_logcycle - lag(salesgen_logcycle),
salessel_log = log(tax_sales_select_real2_state),
salessel_logtrend = hpfilter(salessel_log , freq = 100)$trend,
salessel_logcycle = hpfilter(salessel_log , freq = 100)$cycle,
salessel_dlog = salessel_log - lag(salessel_log),
salessel_dlogtrend= salessel_logtrend - lag(salessel_logtrend),
salessel_dlogcycle = salessel_logcycle - lag(salessel_logcycle),
nonPITsalestot_log = log(tax_nonPITsalestot_real2_state),
nonPITsalestot_logtrend = hpfilter(nonPITsalestot_log, freq = 100)$trend,
nonPITsalestot_logcycle = hpfilter(nonPITsalestot_log, freq = 100)$cycle,
nonPITsalestot_dlog = nonPITsalestot_log - lag(nonPITsalestot_log),
nonPITsalestot_dlogtrend= nonPITsalestot_logtrend - lag(nonPITsalestot_logtrend),
nonPITsalestot_dlogcycle = nonPITsalestot_logcycle - lag(nonPITsalestot_logcycle),
propertyLoc_log = log(tax_property_real2_local),
propertyLoc_logtrend = hpfilter(propertyLoc_log, freq = 100)$trend,
propertyLoc_logcycle = hpfilter(propertyLoc_log, freq = 100)$cycle,
propertyLoc_dlog = propertyLoc_log - lag(propertyLoc_log),
propertyLoc_dlogtrend= propertyLoc_logtrend - lag(propertyLoc_logtrend),
propertyLoc_dlogcycle = propertyLoc_logcycle - lag(propertyLoc_logcycle),
stockIdx_log = log(LCapStock_TRI_real2),
stockIdx_logtrend = hpfilter(stockIdx_log, freq = 100)$trend,
stockIdx_logcycle = hpfilter(stockIdx_log, freq = 100)$cycle,
stockIdx_dlog = stockIdx_log - lag(stockIdx_log),
stockIdx_dlogtrend= stockIdx_logtrend - lag(stockIdx_logtrend),
stockIdx_dlogcycle = stockIdx_logcycle - lag(stockIdx_logcycle),
LagstockIdx_dlog = lag(stockIdx_dlog),
LagstockIdx_dlogtrend = lag(stockIdx_dlogtrend),
LagstockIdx_dlogcycle = lag(stockIdx_dlogcycle),
capgains_log = log(capgains_real2),
capgains_logtrend = hpfilter( capgains_log , freq = 100)$trend,
capgains_logcycle = hpfilter( capgains_log , freq = 100)$cycle,
capgains_dlog = capgains_log - lag(capgains_log),
capgains_dlogtrend= capgains_logtrend - lag(capgains_logtrend),
capgains_dlogcycle = capgains_logcycle - lag(capgains_logcycle),
Lagcapgains_dlog = lag(capgains_dlog),
Lagcapgains_dlogtrend = lag(capgains_dlogtrend),
Lagcapgains_dlogcycle = lag(capgains_dlogcycle),
PIT_GDP_trend = exp(PIT_logtrend - GDP_logtrend),
salesgen_GDP_trend = exp(salesgen_logtrend - GDP_logtrend),
salessel_GDP_trend = exp(salessel_logtrend - GDP_logtrend),
nonPITsalestot_GDP_trend = exp(nonPITsalestot_logtrend - GDP_logtrend),
propertyLoc_GDP_trend = exp(propertyLoc_logtrend - GDP_logtrend)
)
# level and trend
df_decomp_real2 %>% # GDP
select(year, GDP_dlog, GDP_dlogtrend) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
geom_hline(yintercept = 0, linetype = 2)
df_decomp_real2 %>% #PIT
select(year, PIT_dlog, PIT_dlogtrend) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point"))
df_decomp_real2 %>% #gen sales
select(year, salesgen_dlog, salesgen_dlogtrend) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point"))
df_decomp_real2 %>% #gen sales
select(year, stockIdx_dlog, stockIdx_dlogtrend) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point"))
# compare cycles
# log cycle
df_decomp_real2 %>% # GDP, PIT, and gen sales
select(year, GDP_dlogcycle, PIT_dlogcycle, salesgen_dlogcycle) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
geom_hline(yintercept = 0, linetype = 2)
df_decomp_real2 %>% # GDP, gen sales and sel sales
select(year, GDP_dlogcycle, salesgen_dlogcycle, salessel_dlogcycle) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
geom_hline(yintercept = 0, linetype = 2)
df_decomp_real2 %>% # GDP, nonPITsales, and local property
select(year, GDP_dlogcycle, nonPITsalestot_dlogcycle, propertyLoc_dlogcycle) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
geom_hline(yintercept = 0, linetype = 2)
df_decomp_real2 %>% # GDP, PIT, and stock
select(year, GDP_dlogcycle, PIT_dlogcycle, stockIdx_dlogcycle) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
geom_hline(yintercept = 0, linetype = 2)
df_decomp_real2 %>% # PIT, and capgains and stock
select(year, PIT_dlogcycle, stockIdx_dlogcycle, capgains_dlogcycle) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
geom_hline(yintercept = 0, linetype = 2)
# df_decomp_real2 %>% # PIT, and capgains and stock
# mutate() %>%
# select(year, diff_PIT_logcycle, diff_stockIdx_logcycle, diff_capgains_logcycle) %>%
# gather(var, value, -year) %>%
# qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
# geom_hline(yintercept = 0, linetype = 2)
# Trends
df_decomp_real2 %>% # PIT vs gen sales
select(year, PIT_logtrend, salesgen_logtrend) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point"))
# geom_hline(yintercept = 1, linetype = 2)
df_decomp_real2 %>% # PIT vs gen sales as % of GDP
select(year,
PIT_GDP_trend,
salesgen_GDP_trend,
salessel_GDP_trend,
nonPITsalestot_GDP_trend,
propertyLoc_GDP_trend) %>%
gather(var, value, -year) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line", "point")) +
coord_cartesian(ylim = c(0, 0.035))
# geom_hline(yintercept = 1, linetype = 2)
# Check CPI inflation and GDP price index inflation
df_dlreal2 %>%
filter(state_abb == "US") %>%
select(state_abb, year, dlInflation_Index, dlGDPCTPI_FRED) %>%
gather(var, value, -year, -state_abb) %>%
qplot(x = year, y = value, color = var, data = ., geom = c("line","point"))
# GDP price index inflation is generally lower and less volatile.
#*******************************************************************************
# Regression analysis: data prep 2 asset return and PIT ####
#*******************************************************************************
# Goal: Estimate the relationship between real PIT growth, real GSP growth, and asset return (nominal),
# and see if there is structure breek around 2000. (if the recent two recessions are different.)
# Notes:
# Need to first examine the relationship between realized capgains, tax revenue from realized capgains, and asset returns.
# Need an argument for using investment returns in the PIT regression
# 1. Asset returns and captial gains, realized captial gains and PIT
df_temp <-
df_dlreal2 %>%
select(state_abb, year,
dlLCapStock_CAI,
dlLCapStock_TRI,
dlLTGBond_TRI,
LTGBond_Yield,
SP500_return_nyu,
TBond_return_nyu,
capgains_chg,
dlLCapStock_CAI_real2,
dlLCapStock_TRI_real2,
dlLTGBond_TRI_real2,
SP500_return_nyu_real2,
TBond_return_nyu_real2,
capgains_chg_real2,
tax_gains_chg,
dltax_indivIncome_real2_state) %>%
filter(state_abb == "US")
# quick look at how the total bond returns from SBBI and NYU Stern differ
df_temp %>%
select(state_abb, year, dlLTGBond_TRI, TBond_return_nyu) %>%
gather(var, value, -state_abb, -year) %>%
qplot(x = year, y = value, color = var, data=., geom = c("line", "point")) + theme_bw() +
scale_x_continuous(breaks = seq(1950, 2020, 5))
# The two sources show very different returns, especially after 2000.
# We may want to stick with the SBBI return. (SBBI's calculation looks more rigorous)
df_temp %>%
select(state_abb, year, dlLCapStock_TRI, SP500_return_nyu) %>%
gather(var, value, -state_abb, -year) %>%
qplot(x = year, y = value, color = var, data=., geom = c("line", "point")) + theme_bw() +
scale_x_continuous(breaks = seq(1950, 2020, 5))
# It seems there is a lag in SBBI SP500 return
# Plotting asset returns and realized capital gains
# Stock
fig_returnCapGains_nom <-
df_temp %>%
filter(year >=1977) %>%
select(state_abb, year, dlLCapStock_TRI, capgains_chg_real2) %>%
gather(var, value, -state_abb, -year) %>%
mutate(var = factor(var, levels = c("dlLCapStock_TRI", "capgains_chg_real2"),
labels = c("SP500 Total Return", "Change in realized capital gains"))) %>%
qplot(x = year, y = 100 * value, color = var, data=., geom = c("line", "point")) +
theme_bw() + RIG.themeLite() +
scale_x_continuous(breaks = seq(1950, 2020, 5)) +
scale_color_manual(values = c(RIG.green, "blue")) +
labs(x = NULL, y = "Percent", color = NULL,
title = "Total stock returns and realized capital gains") +
theme(legend.position = "bottom")
fig_returnCapGains_nom
fig_returnCapGains_real <-
df_temp %>%
filter(year >=1977) %>%
select(state_abb, year, dlLCapStock_TRI_real2, capgains_chg_real2) %>%
gather(var, value, -state_abb, -year) %>%
mutate(var = factor(var, levels = c("dlLCapStock_TRI_real2", "capgains_chg_real2"),
labels = c("SP500 real total Return", "Change in real realized capital gains"))) %>%
qplot(x = year, y = 100 * value, color = var, data=., geom = c("line", "point")) +
theme_bw() + RIG.themeLite() +
scale_x_continuous(breaks = seq(1950, 2020, 5)) +
scale_color_manual(values = c(RIG.green, "blue")) +
labs(x = NULL, y = "Percent", color = NULL,
title = "Total stock returns and realized capital gains (in real terms)") +
theme(legend.position = "bottom")
fig_returnCapGains_real
# Long-term gov bond, SBBI
df_temp %>%
select(state_abb, year, dlLTGBond_TRI_real2, capgains_chg_real2) %>%
gather(var, value, -state_abb, -year) %>%
qplot(x = year, y = value, color = var, data=., geom = c("line", "point")) + theme_bw() +
scale_x_continuous(breaks = seq(1950, 2020, 5))
# No obvious correlation
df_temp %>%
select(state_abb, year, dlLTGBond_TRI, capgains_chg) %>%
gather(var, value, -state_abb, -year) %>%
qplot(x = year, y = value, color = var, data=., geom = c("line", "point")) + theme_bw() +
scale_x_continuous(breaks = seq(1950, 2020, 5))
# No obvious correlation
# Long-term gov bond, NYU
df_temp %>%
select(state_abb, year, TBond_return_nyu, capgains_chg) %>%
gather(var, value, -state_abb, -year) %>%
qplot(x = year, y = value, color = var, data=., geom = c("line", "point")) + theme_bw() +
scale_x_continuous(breaks = seq(1950, 2020, 5))
#
# Plotting realized captial gains
# High correlation between 1-year lag of realized captial gain and capital gains tax receipts
# High correlation between captial gain tax receipt and state PIT
# Question: the share of capital gain tax in total PIT
# fig_captainsTax <-
# df_temp %>%
# select(state_abb, year, capgains_chg, tax_gains_chg, tax_indivIncome_real_state) %>%
# mutate(capgains_chg = lag(capgains_chg)) %>%
# gather(var, value, -state_abb, -year) %>%
# mutate(var = factor(var, levels = c("capgains_chg", "tax_gains_chg", "tax_indivIncome_real_state"),
# labels = c("Change in realized capital gains (1 year lag)", "Change in capital gains tax receipts", "change in state individual tax"))) %>%
# qplot(x = year, y = 100 * value, color = var, data=., geom = c("line", "point")) +
# theme_bw() + RIG.themeLite() +
# geom_hline(yintercept = 0, linetype = 2) +
# scale_x_continuous(breaks = seq(1950, 2020, 5)) +
# scale_color_manual(values = c("blue", RIG.red, "darkgrey")) +
# labs(x = NULL, y = "Percent", color = NULL,
# title = "Realized capital gains and tax revenues") +
# theme(legend.position = "bottom")
# fig_captainsTax
fig_capgainsTax_real <-
df_temp %>%
filter(year >= 1988) %>%
select(state_abb, year, capgains_chg_real2, dlLCapStock_TRI_real2, dltax_indivIncome_real2_state) %>%
mutate(capgains_chg_real2 = lag(capgains_chg_real2),
dlLCapStock_TRI_real2 = lag(dlLCapStock_TRI_real2)) %>%
gather(var, value, -state_abb, -year) %>%
mutate(var = factor(var, levels = c("capgains_chg_real2", "dlLCapStock_TRI_real2", "dltax_indivIncome_real2_state"),
labels = c("Real change in realized capital gains (1 year lag)", "SP500 total real return (1 year lag)", "Real change in state individual tax"))) %>%
qplot(x = year, y = 100 * value, color = var, data=., geom = c("line", "point")) +
theme_bw() + RIG.themeLite() +
geom_hline(yintercept = 0, linetype = 2) +
scale_x_continuous(breaks = seq(1950, 2020, 5)) +
scale_color_manual(values = c("blue", RIG.red, "darkgrey")) +
labs(x = NULL, y = "Percent", color = NULL,
title = "Realized capital gains and tax revenues (in real terms)") +
theme(legend.position = "bottom")
fig_capgainsTax_real
#*******************************************************************************
# Figures:tax revenues, GDP and asset returns ####
#*******************************************************************************
# Figure: comparing cycles of taxes
df_cyclePct <-
df_decomp_real2 %>%
filter(year >= 1978) %>%
select(state_abb, year,
GDP_logtrend, GDP_logcycle,
PIT_logtrend, PIT_logcycle,
salesgen_logtrend, salesgen_logcycle,
salessel_logtrend, salessel_logcycle,
nonPITsalestot_logtrend, nonPITsalestot_logcycle,
propertyLoc_logtrend, propertyLoc_logcycle) %>%
mutate(GDP_cyclePct = exp(GDP_logcycle) - 1,
PIT_cyclePct = exp(PIT_logcycle) - 1,
salesgen_cyclePct = exp(salesgen_logcycle) - 1,
salessel_cyclePct = exp(salessel_logcycle) - 1,
nonPITsalestot_cyclePct = exp(nonPITsalestot_logcycle) - 1,
propertyLoc_cyclePct = exp(propertyLoc_logcycle) - 1
)
fig_cyclePct <-
df_cyclePct %>%
select(year,
GDP_cyclePct,
PIT_cyclePct,
salesgen_cyclePct,
nonPITsalestot_cyclePct) %>%
gather(var, value, -year) %>%
mutate(var = factor(var, levels = c("GDP_cyclePct", "PIT_cyclePct", "salesgen_cyclePct", "nonPITsalestot_cyclePct"),
labels = c("GDP", "Personal income tax \n(state)", "General sales tax \n(state)", "Non-personal-income-non-sales taxes \n(state)")
)) %>%
ggplot() +
theme_bw() + RIG.themeLite() +
geom_line(aes(x = year, y = 100 * value, color = var)) +
geom_point(aes(x = year, y = 100 * value, color = var, shape = var)) +
geom_hline(yintercept = 0, linetype = 2) +
geom_rect(data = recessionPeriods[-(1:5),],
aes(xmin = peak, xmax = trough,
ymin = -Inf, ymax = Inf), alpha = 0.4, fill = "grey") +
scale_x_continuous(breaks = seq(1950, 2020, 5)) +
scale_y_continuous(breaks = seq(-100, 100, 2)) +
scale_color_manual(values = c(color_GDP, color_PIT, color_salesgen, color_other)) +
scale_shape_manual(values = c(15, 16, 17, 18)) +
labs(x = NULL, y = "Percent above or below trend (%)", color = NULL, shape = NULL,
title = "Cycles in GDP growth and tax revenues",
subtitle = "Calculated using real values (2009 dollar)") +
theme(legend.position = "bottom")
#guides(col = guide_legend(ncol = 3, byrow = TRUE))
# geom_hline(yintercept = 1, linetype = 2)
fig_cyclePct
fig_cyclePct2 <- # paperFigure
df_cyclePct %>%
select(year,
GDP_cyclePct,
PIT_cyclePct,
salesgen_cyclePct,
propertyLoc_cyclePct) %>%
gather(var, value, -year) %>%
mutate(var = factor(var, levels = c("GDP_cyclePct", "PIT_cyclePct","salesgen_cyclePct", "propertyLoc_cyclePct"),
labels = c("GDP", "Personal income tax \n(state)", "General sales tax \n(state)",
"Property tax\n(local)")
)) %>%
ggplot() +
theme_bw() + RIG.themeLite() +
geom_line(aes(x = year, y = 100 * value, color = var)) +
geom_point(aes(x = year, y = 100 * value, color = var, shape = var)) +
geom_hline(yintercept = 0, linetype = 2) +
geom_rect(data = recessionPeriods[-(1:5),],
aes(xmin = peak, xmax = trough,
ymin = -Inf, ymax = Inf), alpha = 0.4, fill = "grey") +
scale_x_continuous(breaks = seq(1950, 2020, 5)) +
scale_y_continuous(breaks = seq(-100, 100, 2)) +
scale_color_manual(values = c(color_GDP, color_PIT, color_salesgen, color_propertyLoc)) +
scale_shape_manual(values = c(15, 16, 17, 18)) +
labs(x = NULL, y = "Percent above or below trend (%)", color = NULL, shape = NULL,
title = "Cycles in GDP growth and tax revenues",
subtitle = "Calculated using real values (2009 dollar)",
caption = "Source: \nFederal Reserve Bank of St. Louis, FRED;\nU.S. Census Bureau, Annual Survey of State and Local Government Finances") +
theme(legend.position = "bottom")
# guides(col = guide_legend(ncol = 3, byrow = TRUE))
# geom_hline(yintercept = 1, linetype = 2)
fig_cyclePct2
ggsave(paste0(dir_fig_out, "fig_GovFin_cyclePct.png"), fig_cyclePct, width = 10*0.8, height = 6*0.8)
ggsave(paste0(dir_fig_out, "fig_GovFin_cyclePct2.png"), fig_cyclePct2 , width = 10*0.8, height = 6*0.85)
# PIT and sales
df_decomp_real2 %>%
filter(year >= 1988) %>%
select(state_abb, year, GDP_dlogcycle, PIT_dlogcycle, salesgen_dlogcycle) %>%
gather(var, value, -state_abb, -year) %>%
mutate(var = factor(var, levels = c("PIT_dlogcycle", "salesgen_dlogcycle", "GDP_dlogcycle"),
labels = c("Real change in state individual tax", "Real change in general sales tax","Real GDP growth" ))) %>%
qplot(x = year, y = 100 * value, color = var, data=., geom = c("line", "point")) +
theme_bw() + RIG.themeLite() +
geom_hline(yintercept = 0, linetype = 2) +
scale_x_continuous(breaks = seq(1950, 2020, 5)) +
scale_color_manual(values = c("blue", RIG.red, "darkgrey")) +
labs(x = NULL, y = "Percent", color = NULL,
title = "Cyclical components of real growth rates of individual income tax, general sales tax, \nand GDP growth and capital gain tax") +
theme(legend.position = "bottom")
# PIT 1: GDP growth, PIT growth and capgains