1
1
---
2
- title : " Comparing ACFRS data with Census Data"
3
- output :
2
+ title : " Data Summary Statistics"
3
+ date : June 11, 2022
4
+ output :
4
5
html_document :
5
6
toc : true
6
7
toc_float : true
7
- toc_depth : 2
8
+ toc_depth : 3
8
9
---
9
10
10
11
``` {r setup, include=FALSE}
11
12
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
12
13
library(tidyverse)
14
+ library(dplyr)
15
+ library(purrr)
16
+ library(kableExtra)
17
+ options(scipen=999)
13
18
```
14
19
15
- ## Read in ACFRS data
20
+
21
+ ##ACFRS Data
22
+ Data was downloaded from website on Jan 11. Filtered out "Non-profit" category
23
+
16
24
``` {r}
17
25
options(scipen=999)
18
26
jan11_site <- rio::import(here::here("data", "CAFRdata_20220111_221828.xlsx"))
@@ -21,19 +29,17 @@ jan11_site %>%
21
29
select(State, Entity, Category,
22
30
`Net Pension Liability`, `Net OPEB Assets`, `Net OPEB Liability`, `Bonds Outstanding`, `Notes Outstanding`,
23
31
Leases, `Loans Outstanding`, `Compensated Absences`, `Total Liabilities`, Revenues) -> d
32
+ head(d)
24
33
25
- d %>% head()
26
34
```
27
35
28
-
29
- ## Read in census data
30
-
36
+ ## Compare with Census Data
31
37
The Census Bureau has national and state debt totals here:
32
38
https://www2.census.gov/programs-surveys/gov-finances/tables/2019/19slsstab1a.xlsx
33
39
and here:
34
40
https://www2.census.gov/programs-surveys/gov-finances/tables/2019/19slsstab1b.xlsx .
35
41
36
- The excel files have 5 components for each state. The column used below is "state & local government amount"
42
+ The excel files has 5 components for each state. The column used below is "state & local government amount"
37
43
38
44
``` {r}
39
45
# first half
@@ -60,15 +66,18 @@ filter(`...1` == "125") %>%
60
66
# joining
61
67
state_local_amount_census <- rbind(state_local_amount1, state_local_amount2)
62
68
69
+ state_local_amount_census
63
70
64
71
```
65
- Census Debt Outstanding
66
72
73
+ Getting state.abb column
67
74
``` {r}
68
- #Getting state.abb column to join with acfrs data later
75
+
76
+ left_join(state_local_amount_census, state_abb)
69
77
state_name_abb <- data.frame(state.abb, state.name) %>%
70
78
rename("Name" = state.name)
71
- dc <- c("DC", "District of Columbia") # state.abb in R does not have DC
79
+
80
+ dc <- c("DC", "District of Columbia")
72
81
73
82
rbind(dc, state_name_abb) %>%
74
83
arrange(Name) -> foo1
@@ -80,11 +89,9 @@ state_local_amount_census %>%
80
89
81
90
debt_outstanding_census <- cbind(foo1, foo2) %>% select(-State) %>%
82
91
rename("State" = state.abb)
83
-
84
- debt_outstanding_census
85
92
```
86
93
87
- ## Compute sum of ` Bonds Outstanding ` , ` Notes Outstanding ` , Leases by state
94
+ Compute sum of ` Bonds Outstanding ` , ` Notes Outstanding ` , ` Leases ` by state
88
95
89
96
``` {r}
90
97
d %>%
@@ -97,18 +104,14 @@ d %>%
97
104
acfrs_debt
98
105
```
99
106
100
- Joining & Comparing census and ACFRS data
101
-
102
107
``` {r}
103
108
acfrs_debt %>%
104
- left_join(debt_outstanding_census) -> comparing_census_acfrs
105
- comparing_census_acfrs
106
- #write_csv(comparing_census_acfrs, "comparing_census_acfrs.csv")
107
- ```
108
-
109
-
110
-
111
-
112
-
109
+ left_join(debt_outstanding_census) %>%
110
+ mutate(ratio = state_sum_bonds_notes_leases - debt_outstanding_census)
113
111
112
+ debt_outstanding_census %>%
113
+ as_tibble() %>%
114
+ as.double(debt_outstanding_census)
115
+ map_dbl(sum)
116
+ ```
114
117
0 commit comments