Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update sic_classification to match the 1987 revision of the US SIC codes #357

Merged
merged 19 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions data-raw/classification_bridge.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,56 @@ naics_classification <- dplyr::select(

usethis::use_data(naics_classification, overwrite = TRUE)

sic_classification_raw <- read_bridge(
file.path("data-raw", "sic_classification.csv")
sic_classification_raw <- readr::read_csv(
"https://raw.githubusercontent.com/saintsjd/sic4-list/master/sic-codes.csv",
col_types = "ccccc"
)

# freeze the data in this package in-case the above link ever gets removed
# readr::write_csv(sic_classification_raw, "data-raw/sic_classification.csv")

sic_classification <- dplyr::mutate(
sic_classification_raw,
sector = dplyr::case_when(
grepl("^371", SIC) ~ "automotive",
SIC %in% c("5012", "5013") ~ "automotive",
grepl("^451", SIC) ~ "aviation",
grepl("^452", SIC) ~ "aviation",
grepl("^324", SIC) ~ "cement",
grepl("^122", SIC) ~ "coal",
grepl("^124", SIC) ~ "coal",
grepl("^13", SIC) ~ "oil and gas",
SIC %in% c("4911", "4931") ~ "power",
SIC %in% c("3312", "3315", "3316", "3317", "3324", "3325", "3462") ~ "steel",
grepl("^44", SIC) ~ "shipping",
TRUE ~ "not in scope"
jdhoffa marked this conversation as resolved.
Show resolved Hide resolved
),
borderline = dplyr::case_when(
grepl("^371", SIC) ~ TRUE,
grepl("^5013", SIC) ~ TRUE,
grepl("^451", SIC) ~ TRUE,
grepl("^452", SIC) ~ TRUE,
jdhoffa marked this conversation as resolved.
Show resolved Hide resolved
grepl("^124", SIC) ~ TRUE,
SIC %in% c("1321", "1381", "1382", "1389") ~ TRUE,
SIC %in% c("4911", "4931") ~ TRUE,
SIC %in% c("3315", "3316", "3317", "3462") ~ TRUE,
SIC %in% c("4482", "4491", "4492", "4493", "4499") ~ TRUE,
TRUE ~ FALSE
jdhoffa marked this conversation as resolved.
Show resolved Hide resolved
),
)

sic_classification <- dplyr::mutate(
sic_classification,
version = "1987"
)

sic_classification <- dplyr::select(
sic_classification_raw,
"description",
"code",
sic_classification,
description = "Description",
code = "SIC",
"sector",
"borderline"
"borderline",
"version"
)

usethis::use_data(sic_classification, overwrite = TRUE)
Expand Down
1 change: 1 addition & 0 deletions data-raw/data_dictionary/sic_classification.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ sic_classification,description,character,Original SIC description
sic_classification,code,character,Original SIC code
sic_classification,sector,character,Associated PACTA sector
sic_classification,borderline,character,Flag indicating if PACTA sector and classification code are a borderline match. The value TRUE indicates that the match is uncertain between the PACTA sector and the classification. The value FALSE indicates that the match is certainly perfect or the classification is certainly out of PACTA's scope.
sic_classification,version,character,Column identifying to which SIC version the code belongs
1,263 changes: 1,006 additions & 257 deletions data-raw/sic_classification.csv

Large diffs are not rendered by default.

Binary file modified data/data_dictionary.rda
Binary file not shown.
Binary file modified data/sector_classifications.rda
Binary file not shown.
Binary file modified data/sic_classification.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/data_dictionary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/psic_classification.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sector_classifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/sic_classification.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/testthat/_snaps/data_dictionary.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tests/testthat/_snaps/sector_classifications.md

Large diffs are not rendered by default.

Loading