Skip to content

Commit

Permalink
re-construct 70s and 80s tract ids (#15)
Browse files Browse the repository at this point in the history
* re-construct 70s and 80s tract ids

* up version

* pad all tract ids to 6 char

* details on tract id construction
  • Loading branch information
erikarasnick authored Jan 20, 2022
1 parent 0ac1050 commit 13a8a61
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
26 changes: 21 additions & 5 deletions 00_make_block_group_shp.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ saveRDS(blk_grps_sf_2000, "block_groups_2000_5072.rds")
# 1990
blk_grps_sf_1990 <- st_read("/Users/RASV5G/Downloads/nhgis0016_shape/nhgis0016_shapefile_tl2000_us_blck_grp_1990/US_blck_grp_1990.shp")

blk_grps_sf_1990 <- st_transform(blk_grps_sf_1990, crs=5072) %>%
blk_grps_sf_1990 <- st_transform(blk_grps_sf_1990, crs=5072)

blk_grps_sf_1990 <- blk_grps_sf_1990 %>%
dplyr::select(fips_block_group_id_1990 = STFID,
geometry) %>%
mutate(fips_block_group_id_1990 = as.character(fips_block_group_id_1990))
Expand All @@ -34,8 +36,15 @@ saveRDS(blk_grps_sf_1990, "block_groups_1990_5072.rds")
# 1980
tracts_sf_1980 <- st_read('/Users/RASV5G/Downloads/nhgis0018_shape/nhgis0018_shapefile_tl2000_us_tract_1980/US_tract_1980.shp')

tracts_sf_1980 <- st_transform(tracts_sf_1980, crs=5072) %>%
dplyr::select(fips_tract_id_1980 = GISJOIN2,
tracts_sf_1980 <- st_transform(tracts_sf_1980, crs=5072)

tracts_sf_1980 <- tracts_sf_1980 %>%
dplyr::mutate(state_fips = stringr::str_sub(NHGISST, 1, 2),
county_fips = stringr::str_sub(NHGISCTY, 1, 3),
tract_fips = stringr::str_sub(GISJOIN, 9, -1),
tract_fips = stringr::str_pad(tract_fips, 6, pad = "0"),
fips_tract_id_1980 = glue::glue('{state_fips}{county_fips}{tract_fips}')) %>%
dplyr::select(fips_tract_id_1980,
geometry) %>%
mutate(fips_tract_id_1980 = as.character(fips_tract_id_1980))

Expand All @@ -44,8 +53,15 @@ saveRDS(tracts_sf_1980, "tracts_1980_5072.rds")
# 1970
tracts_sf_1970 <- st_read('/Users/RASV5G/Downloads/nhgis0018_shape/nhgis0018_shapefile_tl2000_us_tract_1970/US_tract_1970.shp')

tracts_sf_1970 <- st_transform(tracts_sf_1970, crs=5072) %>%
dplyr::select(fips_tract_id_1970 = GISJOIN2,
tracts_sf_1970 <- st_transform(tracts_sf_1970, crs=5072)

tracts_sf_1970 <- tracts_sf_1970 %>%
dplyr::mutate(state_fips = stringr::str_sub(NHGISST, 1, 2),
county_fips = stringr::str_sub(NHGISCTY, 1, 3),
tract_fips = stringr::str_sub(GISJOIN, 9, -1),
tract_fips = stringr::str_pad(tract_fips, 6, pad = "0"),
fips_tract_id_1970 = glue::glue('{state_fips}{county_fips}{tract_fips}')) %>%
dplyr::select(fips_tract_id_1970,
geometry) %>%
mutate(fips_tract_id_1970 = as.character(fips_tract_id_1970))

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## DeGAUSS example call

```sh
docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/census_block_group:0.4.1 my_address_file_geocoded.csv 2010
docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/census_block_group:0.4.2 my_address_file_geocoded.csv 2010
```

* The first argument (`my_address_file_geocoded.csv`) is the name of your geocoded csv file.
Expand Down Expand Up @@ -45,6 +45,8 @@ docker run --rm -v $PWD:/tmp ghcr.io/degauss-org/census_block_group:0.4.1 my_add
| County | State + County | 2+3=5 | Hamilton County | 39061 |
| Census Tract | State + County + Tract | 2+3+6=11 | Tract 32 in Hamilton County | 39061003200 |
| Block Group | State + County + Tract +<br /> Block Group | 2+3+6+1=12 | Block Group 1 in Tract 32 | 390610032001 |

Due to inconsistencies in the 1970 and 1980 tract identifiers, we concatenated the state FIPS (`NHGISST`), county FIPS (`NGHISCTY`), and tract FIPS (the last 4 or 6 digits of `GISJOIN2`) to construct the full `fips_tract_id`. Since the length of tract FIPS codes varied, we padded all tract FIPS to the maximum 6 digits using zeros.

## DeGAUSS details

Expand Down
2 changes: 1 addition & 1 deletion census_block_group.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/local/bin/Rscript

dht::greeting(geomarker_name = 'census_block_group',
version = '0.4.1',
version = '0.4.2',
description = 'adds census block group or tract identifiers to geocoded addresses')

dht::qlibrary(dplyr)
Expand Down

0 comments on commit 13a8a61

Please sign in to comment.