Skip to content

Commit

Permalink
Merge pull request #302 from PSLmodels/pr-move-cd-project-to-subfolder
Browse files Browse the repository at this point in the history
PR move cd project to subfolder
  • Loading branch information
donboyd5 authored Nov 19, 2024
2 parents f1c7c21 + 21229c1 commit 6f3368c
Show file tree
Hide file tree
Showing 49 changed files with 45 additions and 31 deletions.
3 changes: 0 additions & 3 deletions tmd/areas/targets/prepare/.netlify/state.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# prepare
# prepare_cds

# ignore quarto at the root level
/.quarto/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ CDINTERMEDIATE <- fs::path(CDDIR, "intermediate")
CDFINAL <- fs::path(CDDIR, "final")

CDDOCEXTRACT <- "cd_documentation_extracted_from_21incddocguide.docx.xlsx"

TMDHOME <- fs::path(here::here(), "..", "..", "..", "..", "..")
# normalizePath(TMDHOME)
TMDDATA <- fs::path(TMDHOME, "tmd", "storage", "output")
# normalizePath(TMDDATA)
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions tmd/areas/targets/prepare/prepare_cds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# areas / targets / prepare

Contains code and data used to generate sub-national area targets files.

Evolving preparation documentation is available at [this
website](https://tmd-areas-prepare-targets.netlify.app).
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ execute:
freeze: false # auto: during global project renders, re-render only when source changes

book:
title: "Develop targets for subnational areas"
title: "Develop targets for Congressional districts"
subtitle: "Create csv target files for use by area targeting routines"
# author: "Don Boyd"
date: today
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ source(here::here("R", "functions.R"))
vmap <- read_csv(fs::path(CDINTERMEDIATE, "cd_variable_mapping.csv"))
cdirs <- read_csv(fs::path(CDINTERMEDIATE, "cdbasefile_sessions.csv"))
TMDDIR <- here::here("..", "..", "..", "storage", "output")
fpath <- fs::path(TMDDIR, "cached_allvars.csv")
fpath <- fs::path(TMDDATA, "cached_allvars.csv")
tmd2021 <- vroom(fpath)
ns(tmd2021)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ editor_options:
source(here::here("R", "libraries.R"))
source(here::here("R", "constants.R"))
source(here::here("R", "functions.R"))
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ editor_options:
source(here::here("R", "libraries.R"))
source(here::here("R", "constants.R"))
source(here::here("R", "functions.R"))
# 334283385.27000004 national pop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ To re-download data and save to the "../cds/raw_data" folder, set option `eval:
source(here::here("R", "libraries.R"))
source(here::here("R", "constants.R"))
source(here::here("R", "functions.R"))
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ Get the unenhanced target data and the tmd2021 cached data.
stack <- read_csv(fs::path(CDINTERMEDIATE, "cdbasefile_sessions.csv"))
TMDDIR <- here::here("..", "..", "..", "storage", "output")
fpath <- fs::path(TMDDIR, "cached_allvars.csv")
fpath <- fs::path(TMDDATA, "cached_allvars.csv")
tmd2021 <- vroom(fpath)
ns(tmd2021)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// "cdlist": "all", // all, or a list such as ["AK00", "DE00"],
"cdlist": ["NY21"], // all, or a list such as ["AK00", "DE00"],
// "cdlist": ["AK00", "DE00"], // all, or a list such as ["AK00", "DE00"],
// "cdlist": ["AK00", "DE00", "ID01", "ID02", "ME02", "MT00", "ND00", "PA08", "SD00", "WY00"],
// "cdlist": ["AK00", "DE00", "ID01", "ID02", "ME02", "MT00", "ND00", "PA08", "SD00", "WY00"],

// target parameters
"notzero": true, // true or false
Expand All @@ -27,19 +27,19 @@
{
"varname": "c00100",
"scope": 1,
"count": 1,
"count": 2,
"fstatus": 1
},
{
"varname": "c00100",
"scope": 1,
"count": 1,
"count": 2,
"fstatus": 2
},
{
"varname": "c00100",
"scope": 1,
"count": 1,
"count": 2,
"fstatus": 4
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# run from terminal with:
# Rscript create_cdtargets.R phase5.json
# Rscript create_cdtargets.R phase6_add_socsec.json (or phase5.json)

# Rscript test.r > output.log 2>&1

Expand Down Expand Up @@ -125,22 +125,18 @@ if("agi_exclude" %in% names(target_rules)){
# target_stubs

# create a dataframe to match against the stack data for targets
vmap
# vmap
vmap2 <- vmap |>
mutate(fstatus=case_when(basevname=="MARS1" ~ 1,
basevname=="MARS2" ~ 2,
basevname=="MARS4" ~ 4,
.default = 0))
mutate(fstatus=ifelse(str_starts(basevname, "MARS"),
str_sub(basevname, -1),
0),
fstatus=as.integer(fstatus))

targets_matchframe <- target_stubs |>
mutate(sort=row_number() + 1) |>
rows_insert(tibble(varname="XTOT", scope=0, count=0, fstatus=0, agistub=0, sort=1),
by="varname") |>
left_join(vmap2, by = join_by(varname, fstatus), relationship = "many-to-many") |>
mutate(basevname = case_when(fstatus == 1 ~ "MARS1",
fstatus == 2 ~ "MARS2",
fstatus == 4 ~ "MARS4",
.default = basevname)) |>
relocate(sort) |>
arrange(sort)

Expand All @@ -150,7 +146,10 @@ targets_matchframe <- target_stubs |>
##.. filtering Congressional districts ----
cdlist <- unlist(cdrecipe$cdlist)
cdlist
if(cdlist != "all"){
if(
(length(cdlist) > 1) ||
((length(cdlist) ==1) && (cdlist != "all"))
){
cd_filter <- expr(statecd %in% cdlist)
} else if(length(cdlist) == 1 & cdlist == "all") {
cd_filter <- TRUE
Expand Down Expand Up @@ -185,7 +184,17 @@ mapped <- targets_matchframe |>
relationship = "many-to-many") |>
arrange(statecd, sort)

tmp <- stack |>
filter(!!cd_filter,
!!zero_filter,
!!negative_filter,
session %in% cdrecipe$session)
count(tmp, basevname, vname)

tmp |>
filter(basevname=="v00100")

count(stack, count)

# checks
# mapped |> filter(target == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ editor_options:

# Introduction {.unnumbered}

This R project constructs subnational area targets for:
This R project constructs subnational area targets for Congressional districts.

- States (to come)

- Congressional districts (in progress)

In addition, it creates a local web page that a user can upload to a web service if desired. An in-progress version can be viewed on the web [here](https://tmd-areas-prepare-targets.netlify.app/). During development, it may not be identical to what your clone creates.
In addition, it creates a local web page that a user can upload to a web service if desired. An in-progress version can be viewed on the web [here](https://tmd-areas-prepare-cd-targets.netlify.app/). During development, it may not be identical to what your clone creates.

This R project is part of the larger tax-microdata-benchmarking project, and is in the subfolder "tmd/areas/targets/prepare/".
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ At present the code prepares target files with targets we believe are useful and

## To create area weights using the target files in tax-microdata-benchmarking

- copy desired target .csv files from ".../targets/prepare/cds/final/" folder to the ".../targets/" folder
- copy desired target .csv files from ".../targets/prepare/prepare_cds/cdtargets/" folder to the ".../targets/" folder
- follow tax-microdata-benchmarking instructions to run `make_all.py` or \`create_area_weights.py'

## Additional notes
Expand Down

0 comments on commit 6f3368c

Please sign in to comment.