Skip to content

Commit

Permalink
update examination reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
donboyd5 committed Dec 23, 2024
1 parent 3b91107 commit 1234354
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 488 deletions.
109 changes: 109 additions & 0 deletions tmd/areas/targets/prepare/target_recipes/aka.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// run from terminal (not console) with:
// Rscript write_area_target_files.R <filename>

// note: all text values must be in quotes
{
"areatype": "state", // state or cd in quotes

// "suffix": "A", // not present, or null, or a capital letter
// "session": 118, // for areatype cd only: not present, or 117 or 118

// arealist:
// cds: "all", or a list such as ["AK00", "DE00"]
// Phase 4 cds: ["AK00", "DE00", "ID01", "ID02", "ME02", "MT00", "ND00", "PA08", "SD00", "WY00"],
// states: "all", or a list such as ["ak", "de"]
// Phase 6 states: ["AK", "MN", "NJ", "NM", "VA", "SC"] plus SC
// For testing: ["MN"]
"arealist": ["AK"],

// target parameters
"notzero": true, // true or false -- whether to allow zero-valued targets
"notnegative": false, // true or false -- whether to allow negative-valued targets
"targets": [
{
"varname": "c00100", // agi
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 0
},
{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 1 // Single
},

{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 2 // Married joint
},
{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 4 // Head of household
},
{
"varname": "e00200",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e00300",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e01500", // Total pensions and annuities
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e02400",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e18400",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e18400",
"scope": 1,
"count": 2,
"fstatus": 0
},
{
"varname": "e18500",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e18500",
"scope": 1,
"count": 2,
"fstatus": 0
},
{
"varname": "e26270",
"scope": 1,
"count": 0,
"fstatus": 0
}
]
}
35 changes: 25 additions & 10 deletions tmd/areas/targets/prepare/target_recipes/phase6_states.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"areatype": "state", // state or cd in quotes

// "suffix": "A", // not present, or null, or a capital letter
// "suffix": "", // not present, or null, or a capital letter
// "session": 118, // for areatype cd only: not present, or 117 or 118

// arealist:
Expand All @@ -14,11 +14,11 @@
// states: "all", or a list such as ["ak", "de"]
// Phase 6 states: ["AK", "MN", "NJ", "NM", "VA", "SC"] plus SC
// For testing: ["MN"]
"arealist": "all",
"arealist": ["AK", "MN", "NJ", "NM", "VA", "SC"],

// target parameters
"notzero": true, // true or false -- whether to allow zero-valued targets
"notnegative": true, // true or false -- whether to allow negative-valued targets
"notnegative": false, // true or false -- whether to allow negative-valued targets
"targets": [
{
"varname": "c00100", // agi
Expand Down Expand Up @@ -56,7 +56,13 @@
"scope": 1,
"count": 0,
"fstatus": 0
},
},
{
"varname": "e00200",
"scope": 1,
"count": 2,
"fstatus": 0
},
{
"varname": "e00300",
"scope": 1,
Expand All @@ -79,22 +85,31 @@
"varname": "e18400",
"scope": 1,
"count": 0,
"fstatus": 0,
"agi_exclude": [1, 2] // not present, or a vector of agistubs to include
"fstatus": 0
},
{
"varname": "e18400",
"scope": 1,
"count": 2,
"fstatus": 0
},
{
"varname": "e18500",
"scope": 1,
"count": 0,
"fstatus": 0,
"agi_exclude": [1, 2]
"fstatus": 0
},
{
"varname": "e18500",
"scope": 1,
"count": 2,
"fstatus": 0
},
{
"varname": "e26270",
"scope": 1,
"count": 0,
"fstatus": 0,
"agi_exclude": [1, 2, 3] // not present, or a vector of agistubs to include
"fstatus": 0
}
]
}
100 changes: 100 additions & 0 deletions tmd/areas/targets/prepare/target_recipes/phase6_states_bak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// run from terminal (not console) with:
// Rscript write_area_target_files.R <filename>

// note: all text values must be in quotes
{
"areatype": "state", // state or cd in quotes

// "suffix": "A", // not present, or null, or a capital letter
// "session": 118, // for areatype cd only: not present, or 117 or 118

// arealist:
// cds: "all", or a list such as ["AK00", "DE00"]
// Phase 4 cds: ["AK00", "DE00", "ID01", "ID02", "ME02", "MT00", "ND00", "PA08", "SD00", "WY00"],
// states: "all", or a list such as ["ak", "de"]
// Phase 6 states: ["AK", "MN", "NJ", "NM", "VA", "SC"] plus SC
// For testing: ["MN"]
"arealist": "all",

// target parameters
"notzero": true, // true or false -- whether to allow zero-valued targets
"notnegative": true, // true or false -- whether to allow negative-valued targets
"targets": [
{
"varname": "c00100", // agi
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 0
},
{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 1 // Single
},

{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 2 // Married joint
},
{
"varname": "c00100", // agi used to get total count
"scope": 1,
"count": 1,
"fstatus": 4 // Head of household
},
{
"varname": "e00200",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e00300",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e01500", // Total pensions and annuities
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e02400",
"scope": 1,
"count": 0,
"fstatus": 0
},
{
"varname": "e18400",
"scope": 1,
"count": 0,
"fstatus": 0,
"agi_exclude": [1, 2] // not present, or a vector of agistubs to include
},
{
"varname": "e18500",
"scope": 1,
"count": 0,
"fstatus": 0,
"agi_exclude": [1, 2]
},
{
"varname": "e26270",
"scope": 1,
"count": 0,
"fstatus": 0,
"agi_exclude": [1, 2, 3] // not present, or a vector of agistubs to include
}
]
}
14 changes: 14 additions & 0 deletions tmd/areas/targets/prepare/target_recipes/test_variable_mapping.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
varname,basesoivname,description,fstatus
XTOT,XTOT,Population,0
c00100,n1,Total number of returns,0
c00100,mars1,fstatus == 1,1
c00100,mars2,fstatus == 2,2
c00100,mars4,fstatus == 4,4
c00100,00100,Adjusted gross income,0
e00200,00200,Wages,0
e00300,00300,Taxable interest income,0
e01500,tmd01500_shared_by_soi01700,Pensions total,0
e02400,tmd02400_shared_by_soi02500,Social Security total,0
e26270,26270,Combined partnership and S corporation net income/loss,0
e18400,tmd18400_shared_by_soi18400,State and local income or sales taxes,0
e18500,tmd18500_shared_by_soi18500,State and local real estate taxes,0
17 changes: 9 additions & 8 deletions tmd/areas/weights/examine/R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,25 @@ save_enhanced_weighted_sums <- function(taxcalc_vars){

get_combined_file <- function(){

targets_available <- read_csv(fs::path(CONSTANTS$TARGETS_DIR, "enhanced_targets.csv")) |>
rename(area = 1) |> # fix this earlier in process
mutate(area = stringr::str_to_lower(area))
targets_available <- readr::read_csv(fs::path(CONSTANTS$TARGETS_DIR, "enhanced_targets.csv")) |>
dplyr::rename(area = 1) |> # fix this earlier in process
dplyr::mutate(area = stringr::str_to_lower(area))

target_files <- fs::dir_ls(CONSTANTS$WEIGHTS_DIR) |>
str_subset("targets.csv")
stringr::str_subset("targets.csv") |>
stringr::str_subset("enhanced", negate = TRUE) # allows us to have enhanced_targets.csv in folder

targets_used <- vroom::vroom(target_files, id="area") |>
mutate(area = fs::path_file(area),
dplyr::mutate(area = fs::path_file(area),
area = stringr::word(area, sep = "_"),
targeted = TRUE)

wtdsums <- readr::read_csv(fs::path(CONSTANTS$OUTPUT_DIR, "wtdsums_enhanced.csv"))
vmap <- read_csv(fs::path(CONSTANTS$RECIPES_DIR, paste0(CONSTANTS$AREA_TYPE, "_variable_mapping.csv")))
vmap <- readr::read_csv(fs::path(CONSTANTS$RECIPES_DIR, paste0(CONSTANTS$AREA_TYPE, "_variable_mapping.csv")))

combined <- wtdsums |>
rename(fstatus = MARS) |>
mutate(scope = case_when(data_source == 0 ~ 2, # cps only
dplyr::rename(fstatus = MARS) |>
dplyr::mutate(scope = case_when(data_source == 0 ~ 2, # cps only
data_source == 1 ~ 1, # puf only
data_source == 9 ~ 0, # all records
.default = -9), # ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
# \\wsl.localhost\Ubuntu-24.04\home\donboyd5\Documents\python_projects\tax-microdata-benchmarking\tmd\areas\targets\prepare\prepare_states\data\intermediate
# \\wsl.localhost\Ubuntu-24.04\home\donboyd5\Documents\python_projects\tax-microdata-benchmarking\tmd\areas\targets\prepare\prepare_cds\cds\intermediate

# constants.R
# functions_constants.R
get_constants <- function(area_type) {
# Validate input
if (!area_type %in% c("state", "cd")) {
stop("area_type must be either 'state' or 'cd'")
valid_area_types <- c("state", "cd", "test")
if (!area_type %in% valid_area_types) {
stop("area_type must be one of: ", paste(valid_area_types, collapse = ", "))
}

# Common constants
Expand Down Expand Up @@ -42,7 +43,12 @@ get_constants <- function(area_type) {
RAW_DIR = fs::path(constants$TMDAREAS, "targets", "prepare", "prepare_cds", "cds", "raw_data"),
TARGETS_DIR = fs::path(constants$TMDAREAS, "targets", "prepare", "prepare_cds", "cds", "intermediate"),
OUTPUT_DIR = here::here("data_cd")
)
),"test" = dplyr::lst( # allows reference to earlier elements
WEIGHTS_DIR = "/mnt/e/test_states/",
RAW_DIR = WEIGHTS_DIR,
TARGETS_DIR = WEIGHTS_DIR,
OUTPUT_DIR = WEIGHTS_DIR
),
)

# Combine common and area-specific constants
Expand Down
2 changes: 1 addition & 1 deletion tmd/areas/weights/examine/_area-template_dt.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ areatab <- compfile |>
.default = x))) |>
DT::datatable(rownames = FALSE,
options = list(order = list(1, "asc"), # use 2nd column (1) for sorting
scrollX = TRUE, scrollY = TRUE, paging = TRUE, pageLength = 20,
scrollX = TRUE, scrollY = TRUE, paging = TRUE, pageLength = 25,
autoWidth = TRUE),
filter="top",
escape = FALSE) |>
Expand Down
7 changes: 3 additions & 4 deletions tmd/areas/weights/examine/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ execute:
eval: true
echo: true
output: true
freeze: auto # auto: during global project renders, re-render only when source changes
freeze: false # auto: during global project renders, re-render only when source changes

book:
title: "Examine results using area weights"
Expand All @@ -40,10 +40,9 @@ book:
# - cd_comparison_summary.qmd
- part: "Examine states"
chapters:
- state_analysis.qmd
- state_data_preparation.qmd
- state_summary_analysis.qmd
- individual_state_reports.qmd
# - state_get_and_save_state_weights.qmd
# - state_get_tmd_and_summarize_and_save_state_weighted_results.qmd

format:
html:
Expand Down
Loading

0 comments on commit 1234354

Please sign in to comment.