|
| 1 | +--- |
| 2 | +title: "Comparing Total_liability vs Sum of the components" |
| 3 | +output: html_document |
| 4 | +--- |
| 5 | + |
| 6 | +```{r setup, include=FALSE} |
| 7 | +knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE) |
| 8 | +library(tidyverse) |
| 9 | +library(writexl) |
| 10 | +``` |
| 11 | + |
| 12 | +#### Read in data |
| 13 | + |
| 14 | +```{r} |
| 15 | +dec23 <- rio::import(here::here("data", "data-Dec23-2-tn.csv")) |
| 16 | +
|
| 17 | +# data dimension |
| 18 | +dim(dec23) |
| 19 | +``` |
| 20 | + |
| 21 | +The first few rows of the data |
| 22 | + |
| 23 | +```{r} |
| 24 | +head(dec23) |
| 25 | +``` |
| 26 | + |
| 27 | +Summing up the following components to get column "sum_components": |
| 28 | +bonds_outstanding + compensated_absences + leases + loans_outstanding + net_pension_liability + net_opeb_liability. |
| 29 | + |
| 30 | +Filter for rows that have sum_components - total_liabilities > 0 |
| 31 | + |
| 32 | +```{r} |
| 33 | +dec23 %>% |
| 34 | +mutate(sum_components = (bonds_outstanding + compensated_absences + leases + loans_outstanding + |
| 35 | + net_pension_liability + net_opeb_liability)) %>% |
| 36 | + mutate(sum_components_bigger = ifelse(sum_components - total_liabilities > 0, "Y", "N")) %>% |
| 37 | + filter(sum_components_bigger == "Y") -> result2 |
| 38 | +
|
| 39 | +result2 %>% head() |
| 40 | +#write_xlsx(result2, "sum_component_bigger_total_liabilities.xlsx") |
| 41 | +``` |
| 42 | + |
| 43 | +Result: there are `r nrow(result2)` cases where the sum of components bigger than total_liabilities |
| 44 | + |
| 45 | + |
| 46 | +#### Data Queried on December 23 using this: |
| 47 | +(Reuse Marc's code, cut off some fields & conditions) |
| 48 | + |
| 49 | +select cafrs_state.abbreviation as state, cafrs_entity.name, cafrs_entity.category, |
| 50 | + |
| 51 | +total_liabilities, bonds_outstanding, compensated_absences, leases, loans_outstanding, |
| 52 | + |
| 53 | +net_pension_liability, |
| 54 | + |
| 55 | +net_opeb_liability |
| 56 | + |
| 57 | +from cafrs_entity |
| 58 | + |
| 59 | +inner join cafrs_state on (cafrs_entity.state_id = cafrs_state.id) |
| 60 | + |
| 61 | +inner join cafrs_cafr on (cafrs_cafr.entity_id = cafrs_entity.id) |
| 62 | + |
| 63 | +inner join cafrs_netposition on (cafrs_cafr.id = cafrs_netposition.cafr_id) |
| 64 | + |
| 65 | +inner join cafrs_activities on (cafrs_cafr.id = cafrs_activities.cafr_id) |
| 66 | + |
| 67 | +inner join cafrs_proprietaryrevenues on (cafrs_cafr.id = cafrs_proprietaryrevenues.cafr_id) |
| 68 | + |
| 69 | +where category <> 'Non-Profit' |
| 70 | + |
| 71 | +and cafrs_cafr.year = 2020 |
| 72 | + |
| 73 | +and not is_nonstandard |
| 74 | + |
| 75 | +and is_valid |
| 76 | + |
| 77 | +and reviewed_date is not null |
| 78 | + |
| 79 | + |
0 commit comments