# Categorizing individual Census Codes into NHIS Detailed Categories as described here: National Center for Health Statistics.
# Dataset documentation 2018. Document Version Date: 25 July 2022. National Health Interview Survey (NHIS).
# Available from:
# https://ftp.cdc.gov/pub/health_Statistics/NCHs/Dataset_Documentation/NHIS/2021/Adult-codebook.pdf
# See Industry Appendix page 623, and Occupation Appendix page 626.;
# Please note:
# NHIS 2018 INDUSTRY AND OCCUPATION GROUPINGS uses the 2012 Census codes;
# NHIS 2021 INDUSTRY AND OCCUPATION GROUPINGS uses the 2018 Census codes;
#
# Mortality data starting with 2023 use 2018 census codes;
# Email noms@cdc.gov with any questions on this program;
# Code Created by Hannah Free at the National Institute for Occupational Safety and Health (NIOSH), United States Centers for Disease Control and Prevention.
#Basic Setup------------------------------------------------------------------------------------------------------------
setwd() #Set working directory to your data by adding path
library(summarytools)
library(tidyverse)
library(dplyr)
library(data.table)
#Read in your data. Reading in as a CSV or as a fixed width text file is recommended. Make sure that variables that start with 0 are not truncated.
#If using a fixed width file for mortality text file, refer to the R mortality read-in code or clean data into a usable format before loading.
#iotable <- read_fwf("Your_data_path_here")
iotable <- df
#Filter to only include 15-120 age range
iotable <- dplyr::filter(iotable, Age_Recode_12 == "04" | Age_Recode_12 == "05" | Age_Recode_12 == "06" | Age_Recode_12 == "07" | Age_Recode_12 == "08" | Age_Recode_12 == "09" | Age_Recode_12 == "10" | Age_Recode_12 == "11" )
#Remove non-residents from sample
iotable <- dplyr::filter(iotable, Resident_Status_US != "4")
#Removing any blanks
iotable <- iotable %>% drop_na(CensusOcc)
iotable <- iotable %>% drop_na(CensusInd)
# # Alternative option to read in full data set as a text file. For the text file, you must specify colClasses as character for this procedure. Make sure that variables that start with 0 are not truncated.
# #iotable <- read.delim("Path_to_your_data", colClasses = "character")
# #Filter by age range, resident status and missing values.
# iotable <- dplyr::filter(iotable, Age_Recode_12 == "04" | Age_Recode_12 == "05" | Age_Recode_12 == "06" | Age_Recode_12 == "07" | Age_Recode_12 == "08" | Age_Recode_12 == "09" | Age_Recode_12 == "10" | Age_Recode_12 == "11" )
# iotable <- dplyr::filter(iotable, Resident_Status_US != "4")
# iotable <- iotable %>% drop_na(CensusOcc)
# iotable <- na_if(iotable, '')
# iotable <- iotable %>% drop_na(CensusOcc)
# iotable <- iotable %>% drop_na(CensusInd)
# # Optional check to confirm that data cleaning worked
# # freq(iotable$Age_Recode_12)
# # freq(iotable$Age_Recode_12)
# # freq(iotable$Resident_Status_US)
#For this recode, you will need individual census occupation and industry code character variables named:
#CensusOcc
#CensusInd
#------------------------------------------------------------------------------------------------------------------------
#2010 4-digit census occupation codes (from 2010 SOC) recoded to 2018 NHIS detailed recodes for occupation =occ_detailed
#2007/2012 NAICS-based census industry codes recoded to 2018 NHIS detailed recodes for industry =ind_detailed
#includes codes for 2007 since there was a one-to-one match for census codes see:
# https://www.census.gov/topics/employment/industry-occupation/guidance/code-lists.html
#includes industry code 2780 metal forgings and stampings, which was in the detailed recode but not the simple
#includes NIOSH/NCHS non-paid worker codes and military codes see:
# /niosh/topics/coding/nioccsuserdocumentation.html
#-----------------------------------------------------------------------------
#Code to change census occupation codes into NHIS detailed codes
iotable <- iotable %>%
mutate(occ_detailed = case_when(
CensusOcc %in% c("0010", "0020", "0030") ~ "01",
CensusOcc %in% c("0040", "0051", "0052", "0060") ~ "02",
CensusOcc %in% c("0101", "0102", "0110", "0120", "0135", "0136", "0137", "0140", "0150", "0160") ~ "03",
CensusOcc %in% c("0205", "0220", "0230", "0300", "0310", "0325", "0335", "0340", "0350", "0360", "0400", "0410", "0420", "0425", "0426", "0440") ~ "04",
CensusOcc %in% c("0500", "0510", "0520", "0530", "0540", "0565", "0600", "0630", "0640", "0650", "0700", "0705", "0710", "0725", "0726", "0735", "0750") ~ "05",
CensusOcc %in% c("0800", "0810", "0820", "0830", "0845", "0850", "0860", "0900", "0910", "0930", "0940", "0960") ~ "06",
CensusOcc %in% c("1005", "1006", "1007", "1010", "1021", "1022", "1031", "1032", "1050", "1065", "1105", "1106", "1108") ~ "07",
CensusOcc %in% c("1200", "1210", "1220", "1230", "1240") ~ "08",
CensusOcc %in% c("1305", "1306", "1310") ~ "09",
CensusOcc %in% c("1320", "1330", "1340", "1350", "1360", "1400", "1410", "1420", "1430", "1440", "1450", "1460", "1500", "1510", "1520", "1530") ~ "10",
CensusOcc %in% c("1541", "1545", "1551", "1555", "1560") ~ "11",
CensusOcc %in% c("1600", "1610", "1640", "1650", "1660") ~ "12",
CensusOcc %in% c("1700", "1710", "1720", "1745", "1750", "1760") ~ "13",
CensusOcc %in% c("1800", "1815", "1821", "1822", "1825", "1830", "1840", "1860") ~ "14",
CensusOcc %in% c("1900", "1910", "1920", "1935", "1940", "1950", "1970", "1980") ~ "15",
CensusOcc %in% c("2001", "2002", "2003", "2004", "2005", "2006", "2011", "2012", "2013", "2014", "2015", "2016", "2025") ~ "16",
CensusOcc %in% c("2040", "2050", "2060") ~ "17",
CensusOcc %in% c("2100", "2105", "2110") ~ "18",
CensusOcc %in% c("2145", "2170", "2180") ~ "19",
CensusOcc %in% c("2205") ~ "20",
CensusOcc %in% c("2300", "2310", "2320", "2330") ~ "21",
CensusOcc %in% c("2350", "2360") ~ "22",
CensusOcc %in% c("2400", "2435", "2440") ~ "23",
CensusOcc %in% c("2545", "2555") ~ "24",
CensusOcc %in% c("2600", "2631", "2632", "2633", "2634", "2635", "2636", "2640") ~ "25",
CensusOcc %in% c("2700", "2710", "2721", "2722", "2723", "2740", "2751", "2752", "2755", "2770") ~ "26",
CensusOcc %in% c("2805", "2810", "2825", "2830", "2840", "2850", "2861", "2862", "2865") ~ "27",
CensusOcc %in% c("2905", "2910", "2920", "2970") ~ "28",
CensusOcc %in% c("3000", "3010", "3030", "3040", "3050", "3065", "3070", "3090", "3100", "3110", "3120", "3140", "3150", "3160", "3200", "3210", "3220", "3230", "3235", "3245", "3250", "3255", "3256", "3257", "3258", "3261", "3270") ~ "29",
CensusOcc %in% c("3300", "3310", "3321", "3322", "3323", "3324", "3330", "3401", "3402", "3421", "3422", "3423", "3424", "3430", "3500", "3515", "3520", "3545") ~ "30",
CensusOcc %in% c("3550") ~ "31",
CensusOcc %in% c("3601", "3602", "3603", "3605") ~ "32",
CensusOcc %in% c("3610", "3620") ~ "33",
CensusOcc %in% c("3630", "3640", "3645", "3646", "3647", "3648", "3649", "3655") ~ "34",
CensusOcc %in% c("3700", "3710", "3720", "3725", "3735") ~ "35",
CensusOcc %in% c("3740", "3750") ~ "36",
CensusOcc %in% c("3801", "3802", "3820", "3830", "3840", "3870") ~ "37",
CensusOcc %in% c("3900", "3910", "3930", "3940", "3945", "3946", "3960") ~ "38",
CensusOcc %in% c("4000", "4010") ~ "39",
CensusOcc %in% c("4020", "4030") ~ "40",
CensusOcc %in% c("4040", "4055", "4110", "4120") ~ "41",
CensusOcc %in% c("4130", "4140", "4150", "4160") ~ "42",
CensusOcc %in% c("4200", "4210") ~ "43",
CensusOcc %in% c("4220", "4230", "4240") ~ "44",
CensusOcc %in% c("4251", "4252", "4255") ~ "45",
CensusOcc %in% c("4330") ~ "46",
CensusOcc %in% c("4340", "4350") ~ "47",
CensusOcc %in% c("4400", "4420", "4435") ~ "48",
CensusOcc %in% c("4461", "4465") ~ "49",
CensusOcc %in% c("4500", "4510", "4521", "4522", "4525") ~ "50",
CensusOcc %in% c("4530", "4540") ~ "51",
CensusOcc %in% c("4600", "4621", "4622", "4640", "4655") ~ "52",
CensusOcc %in% c("4700", "4710") ~ "53",
CensusOcc %in% c("4720", "4740", "4750", "4760") ~ "54",
CensusOcc %in% c("4800", "4810", "4820", "4830", "4840") ~ "55",
CensusOcc %in% c("4850") ~ "56",
CensusOcc %in% c("4900", "4920", "4930", "4940", "4950", "4965") ~ "57",
CensusOcc %in% c("5000") ~ "58",
CensusOcc %in% c("5010", "5020", "5040") ~ "59",
CensusOcc %in% c("5100", "5110", "5120", "5130", "5140", "5150", "5160", "5165") ~ "60",
CensusOcc %in% c("5200", "5210", "5220", "5230", "5240", "5250", "5260", "5300", "5310", "5320", "5330", "5340", "5350", "5360", "5400", "5410", "5420") ~ "61",
CensusOcc %in% c("5500", "5510", "5521", "5522", "5530", "5540", "5550", "5560", "5600", "5610", "5630") ~ "62",
CensusOcc %in% c("5710", "5720", "5730", "5740") ~ "63",
CensusOcc %in% c("5810", "5820", "5830", "5840", "5850", "5860", "5900", "5910", "5920", "5940") ~ "64",
CensusOcc %in% c("6005") ~ "65",
CensusOcc %in% c("6010", "6020", "6040", "6050") ~ "66",
CensusOcc %in% c("6115") ~ "67",
CensusOcc %in% c("6120", "6130") ~ "68",
CensusOcc %in% c("6200") ~ "69",
CensusOcc %in% c("6210", "6220", "6230", "6240", "6250", "6260", "6305", "6330", "6355", "6360", "6400", "6410", "6441", "6442", "6460", "6500", "6515", "6520", "6530", "6540") ~ "70",
CensusOcc %in% c("6600") ~ "71",
CensusOcc %in% c("6660", "6700", "6710", "6720", "6730", "6740", "6750", "6765") ~ "72",
CensusOcc %in% c("6800", "6821", "6825", "6835", "6850", "6920", "6950") ~ "73",
CensusOcc %in% c("7000") ~ "74",
CensusOcc %in% c("7010", "7020", "7030", "7040", "7050", "7100", "7110", "7120", "7130") ~ "75",
CensusOcc %in% c("7140", "7150", "7160", "7200", "7210", "7220", "7240", "7260") ~ "76",
CensusOcc %in% c("7300", "7315", "7320", "7330", "7340", "7350", "7360", "7410", "7420", "7430", "7440", "7510", "7520", "7540", "7550", "7560", "7610", "7640") ~ "77",
CensusOcc %in% c("7700") ~ "78",
CensusOcc %in% c("7710", "7720", "7730", "7740", "7750") ~ "79",
CensusOcc %in% c("7800", "7810", "7830", "7840", "7850", "7855") ~ "80",
CensusOcc %in% c("7905", "7925", "7950", "8000", "8025", "8030", "8040", "8060", "8100", "8130", "8140", "8225") ~ "81",
CensusOcc %in% c("8250", "8255", "8256") ~ "82",
CensusOcc %in% c("8300", "8310", "8320", "8335", "8350", "8365", "8450", "8465") ~ "83",
CensusOcc %in% c("8500", "8510", "8530", "8540", "8555") ~ "84",
CensusOcc %in% c("8600", "8610", "8620", "8630") ~ "85",
CensusOcc %in% c("8640", "8650", "8710", "8720", "8730", "8740", "8750", "8760", "8800", "8810", "8830", "8850", "8910", "8920", "8930", "8940", "8950", "8865", "8990") ~ "86",
CensusOcc %in% c("9005") ~ "87",
CensusOcc %in% c("9030", "9040", "9050") ~ "88",
CensusOcc %in% c("9110", "9121", "9122", "9130", "9141", "9142", "9150") ~ "89",
CensusOcc %in% c("9210", "9240", "9265") ~ "90",
CensusOcc %in% c("9300", "9310", "9330") ~ "91",
CensusOcc %in% c("9350", "9365", "9410", "9415", "9430") ~ "92",
CensusOcc %in% c("9510", "9570", "9600", "9610", "9620", "9630", "9640", "9645", "9650", "9720", "9760") ~ "93",
CensusOcc %in% c("9830", "9840", "9850") ~ "94",
CensusOcc %in% c("9010", "9020", "9070", "9060", "9100", "9900") ~ "95",
TRUE ~ "00"))
#-------------------------------------------------------------------------------------------------------------------------
#For Census codes, switch NIOSH NCHS military with:
# CensusOcc %in% c("9800", "9810", "9820", "9830", "9840") ~ "23",
#and add:
# CensusOcc %in% c("9997") ~ "97",
# CensusOcc %in% c("9998") ~ "98",
# CensusOcc %in% c("9999") ~ "99",
#-------------------------------------------------------------------------------------------------------------------------
#Create recode for occupation titles
iotable <- iotable %>%
mutate(occ.names = case_when(
CensusOcc %in% "01" ~ "01 Chief executives; general and operations managers; legislators",
CensusOcc %in% "02" ~ "02 Advertising, marketing, promotions, public relations, and sales managers",
CensusOcc %in% "03" ~ "03 Administrative services, compensation/benefits, human resources, training, production, purchasing, and transportion/distribution, and other operations managers",
CensusOcc %in% "04" ~ "04 All other management occupations",
CensusOcc %in% "05" ~ "05 Business operations specialists",
CensusOcc %in% "06" ~ "06 Financial specialists",
CensusOcc %in% "07" ~ "07 Computer specialists",
CensusOcc %in% "08" ~ "08 Mathematical science occupations",
CensusOcc %in% "09" ~ "09 Architects, surveyors, and cartographers",
CensusOcc %in% "10" ~ "10 Engineers",
CensusOcc %in% "11" ~ "11 Drafters, engineering, and mapping technicians",
CensusOcc %in% "12" ~ "12 Life scientists",
CensusOcc %in% "13" ~ "13 Physical scientists",
CensusOcc %in% "14" ~ "14 Social scientists and related workers",
CensusOcc %in% "15" ~ "15 Life, physical, and social science technicians",
CensusOcc %in% "16" ~ "16 Counselors, social workers, and other community and social service specialists",
CensusOcc %in% "17" ~ "17 Religious workers",
CensusOcc %in% "18" ~ "18 Lawyers, judges, and related workers",
CensusOcc %in% "19" ~ "19 Legal support workers",
CensusOcc %in% "20" ~ "20 Postsecondary teachers",
CensusOcc %in% "21" ~ "21 Primary, secondary, and special education school teachers",
CensusOcc %in% "22" ~ "22 Other teachers and instructors",
CensusOcc %in% "23" ~ "23 Librarians, curators, and archivists",
CensusOcc %in% "24" ~ "24 Other education, training, and library occupations",
CensusOcc %in% "25" ~ "25 Art and design workers",
CensusOcc %in% "26" ~ "26 Entertainers and performers, sports and related workers",
CensusOcc %in% "27" ~ "27 Media and communication workers",
CensusOcc %in% "28" ~ "28 Media and communication equipment workers",
CensusOcc %in% "29" ~ "29 Health diagnosing and treating practitioners",
CensusOcc %in% "30" ~ "30 Health technologists and technicians",
CensusOcc %in% "31" ~ "31 Other healthcare practitioners and technical occupations",
CensusOcc %in% "32" ~ "32 Nursing, psychiatric, and home health aides",
CensusOcc %in% "33" ~ "33 Occupational and physical therapist assistants and aides",
CensusOcc %in% "34" ~ "34 Other healthcare support occupations",
CensusOcc %in% "35" ~ "35 First-line supervisors/managers, protective service workers",
CensusOcc %in% "36" ~ "36 Firefighting and prevention workers",
CensusOcc %in% "37" ~ "37 Law enforcement workers",
CensusOcc %in% "38" ~ "38 Other protective service workers",
CensusOcc %in% "39" ~ "39 Supervisors, food preparation, and serving workers",
CensusOcc %in% "40" ~ "40 Cooks and food preparation workers",
CensusOcc %in% "41" ~ "41 Food and beverage serving working",
CensusOcc %in% "42" ~ "42 Other food preparation and serving related workers",
CensusOcc %in% "43" ~ "43 Supervisors, building and grounds cleaning and maintenance workers",
CensusOcc %in% "44" ~ "44 Building cleaning and pest control workers",
CensusOcc %in% "45" ~ "45 Grounds maintenance workers",
CensusOcc %in% "46" ~ "46 Supervisors, personal care and service workers",
CensusOcc %in% "47" ~ "47 Animal care and service workers",
CensusOcc %in% "48" ~ "48 Entertainment attendants and related workers",
CensusOcc %in% "49" ~ "49 Funeral service workers",
CensusOcc %in% "50" ~ "50 Personal appearance workers",
CensusOcc %in% "51" ~ "51 Transportation, tourism, and lodging attendants",
CensusOcc %in% "52" ~ "52 Other personal care and service workers",
CensusOcc %in% "53" ~ "53 Supervisors, sales workers",
CensusOcc %in% "54" ~ "54 Retail sales workers",
CensusOcc %in% "55" ~ "55 Sales representatives, services",
CensusOcc %in% "56" ~ "56 Sales representatives, wholesale and manufacturing",
CensusOcc %in% "57" ~ "57 Other sales and related workers",
CensusOcc %in% "58" ~ "58 Supervisors, office and administrative support workers",
CensusOcc %in% "59" ~ "59 Communications equipment operators",
CensusOcc %in% "60" ~ "60 Financial clerks",
CensusOcc %in% "61" ~ "61 Information and record clerks",
CensusOcc %in% "62" ~ "62 Material recording, scheduling, dispatching, and distributing workers",
CensusOcc %in% "63" ~ "63 Secretaries and administrative assistants",
CensusOcc %in% "64" ~ "64 Other office and administrative support workers",
CensusOcc %in% "65" ~ "65 Supervisors, farming, fishing, and forestry workers",
CensusOcc %in% "66" ~ "66 Agricultural workers",
CensusOcc %in% "67" ~ "67 Fishing and hunting workers",
CensusOcc %in% "68" ~ "68 Forest, conservation, and logging workers",
CensusOcc %in% "69" ~ "69 Supervisors, construction and extraction workers",
CensusOcc %in% "70" ~ "70 Construction trades workers",
CensusOcc %in% "71" ~ "71 Helpers, construction trades",
CensusOcc %in% "72" ~ "72 Other construction and related workers",
CensusOcc %in% "73" ~ "73 Extraction workers",
CensusOcc %in% "74" ~ "74 Supervisors of installation, maintenance, and repair workers",
CensusOcc %in% "75" ~ "75 Electrical and electronic equipment mechanics, installers, and repairers",
CensusOcc %in% "76" ~ "76 Vehicle and mobile equipment mechanics, installers, and repairers",
CensusOcc %in% "77" ~ "77 Other installation, maintenance, and repair occupations",
CensusOcc %in% "78" ~ "78 Supervisors, production workers",
CensusOcc %in% "79" ~ "79 Assemblers and fabricators",
CensusOcc %in% "80" ~ "80 Food processing workers",
CensusOcc %in% "81" ~ "81 Metal workers and plastic workers",
CensusOcc %in% "82" ~ "82 Printing workers",
CensusOcc %in% "83" ~ "83 Textile, apparel, and furnishings workers",
CensusOcc %in% "84" ~ "84 Woodworkers",
CensusOcc %in% "85" ~ "85 Plant and system operators",
CensusOcc %in% "86" ~ "86 Other production occupations",
CensusOcc %in% "87" ~ "87 Supervisors, transportation and material moving workers",
CensusOcc %in% "88" ~ "88 Air transportation workers",
CensusOcc %in% "89" ~ "89 Motor vehicle operators",
CensusOcc %in% "90" ~ "90 Rail transportation workers",
CensusOcc %in% "91" ~ "91 Water transportation workers",
CensusOcc %in% "92" ~ "92 Other transportation workers",
CensusOcc %in% "93" ~ "93 Material moving workers",
CensusOcc %in% "94" ~ "94 NIOSH NCHS military",
CensusOcc %in% "95" ~ "95 NIOSH NCHS Other--Misc",
CensusOcc %in% c("0010", "0020", "0030") ~ "01",
CensusOcc %in% c("0040", "0051", "0052", "0060") ~ "02",
CensusOcc %in% c("0101", "0102", "0110", "0120", "0135", "0136", "0137", "0140", "0150", "0160") ~ "03",
CensusOcc %in% c("0205", "0220", "0230", "0300", "0310", "0325", "0335", "0340", "0350", "0360", "0400", "0410", "0420", "0425", "0426", "0440") ~ "04",
CensusOcc %in% c("0500", "0510", "0520", "0530", "0540", "0565", "0600", "0630", "0640", "0650", "0700", "0705", "0710", "0725", "0726", "0735", "0750") ~ "05",
CensusOcc %in% c("0800", "0810", "0820", "0830", "0845", "0850", "0860", "0900", "0910", "0930", "0940", "0960") ~ "06",
CensusOcc %in% c("1005", "1006", "1007", "1010", "1021", "1022", "1031", "1032", "1050", "1065", "1105", "1106", "1108") ~ "07",
CensusOcc %in% c("1200", "1210", "1220", "1230", "1240") ~ "08",
CensusOcc %in% c("1305", "1306", "1310") ~ "09",
CensusOcc %in% c("1320", "1330", "1340", "1350", "1360", "1400", "1410", "1420", "1430", "1440", "1450", "1460", "1500", "1510", "1520", "1530") ~ "10",
CensusOcc %in% c("1541", "1545", "1551", "1555", "1560") ~ "11",
CensusOcc %in% c("1600", "1610", "1640", "1650", "1660") ~ "12",
CensusOcc %in% c("1700", "1710", "1720", "1745", "1750", "1760") ~ "13",
CensusOcc %in% c("1800", "1815", "1821", "1822", "1825", "1830", "1840", "1860") ~ "14",
CensusOcc %in% c("1900", "1910", "1920", "1935", "1940", "1950", "1970", "1980") ~ "15",
CensusOcc %in% c("2001", "2002", "2003", "2004", "2005", "2006", "2011", "2012", "2013", "2014", "2015", "2016", "2025") ~ "16",
CensusOcc %in% c("2040", "2050", "2060") ~ "17",
CensusOcc %in% c("2100", "2105", "2110") ~ "18",
CensusOcc %in% c("2145", "2170", "2180") ~ "19",
CensusOcc %in% c("2205") ~ "20",
CensusOcc %in% c("2300", "2310", "2320", "2330") ~ "21",
CensusOcc %in% c("2350", "2360") ~ "22",
CensusOcc %in% c("2400", "2435", "2440") ~ "23",
CensusOcc %in% c("2545", "2555") ~ "24",
CensusOcc %in% c("2600", "2631", "2632", "2633", "2634", "2635", "2636", "2640") ~ "25",
CensusOcc %in% c("2700", "2710", "2721", "2722", "2723", "2740", "2751", "2752", "2755", "2770") ~ "26",
CensusOcc %in% c("2805", "2810", "2825", "2830", "2840", "2850", "2861", "2862", "2865") ~ "27",
CensusOcc %in% c("2905", "2910", "2920", "2970") ~ "28",
CensusOcc %in% c("3000", "3010", "3030", "3040", "3050", "3065", "3070", "3090", "3100", "3110", "3120", "3140", "3150", "3160", "3200", "3210", "3220", "3230", "3235", "3245", "3250", "3255", "3256", "3257", "3258", "3261", "3270") ~ "29",
CensusOcc %in% c("3300", "3310", "3321", "3322", "3323", "3324", "3330", "3401", "3402", "3421", "3422", "3423", "3424", "3430", "3500", "3515", "3520", "3545") ~ "30",
CensusOcc %in% c("3550") ~ "31",
CensusOcc %in% c("3601", "3602", "3603", "3605") ~ "32",
CensusOcc %in% c("3610", "3620") ~ "33",
CensusOcc %in% c("3630", "3640", "3645", "3646", "3647", "3648", "3649", "3655") ~ "34",
CensusOcc %in% c("3700", "3710", "3720", "3725", "3735") ~ "35",
CensusOcc %in% c("3740", "3750") ~ "36",
CensusOcc %in% c("3801", "3802", "3820", "3830", "3840", "3870") ~ "37",
CensusOcc %in% c("3900", "3910", "3930", "3940", "3945", "3946", "3960") ~ "38",
CensusOcc %in% c("4000", "4010") ~ "39",
CensusOcc %in% c("4020", "4030") ~ "40",
CensusOcc %in% c("4040", "4055", "4110", "4120") ~ "41",
CensusOcc %in% c("4130", "4140", "4150", "4160") ~ "42",
CensusOcc %in% c("4200", "4210") ~ "43",
CensusOcc %in% c("4220", "4230", "4240") ~ "44",
CensusOcc %in% c("4251", "4252", "4255") ~ "45",
CensusOcc %in% c("4330") ~ "46",
CensusOcc %in% c("4340", "4350") ~ "47",
CensusOcc %in% c("4400", "4420", "4435") ~ "48",
CensusOcc %in% c("4461", "4465") ~ "49",
CensusOcc %in% c("4500", "4510", "4521", "4522", "4525") ~ "50",
CensusOcc %in% c("4530", "4540") ~ "51",
CensusOcc %in% c("4600", "4621", "4622", "4640", "4655") ~ "52",
CensusOcc %in% c("4700", "4710") ~ "53",
CensusOcc %in% c("4720", "4740", "4750", "4760") ~ "54",
CensusOcc %in% c("4800", "4810", "4820", "4830", "4840") ~ "55",
CensusOcc %in% c("4850") ~ "56",
CensusOcc %in% c("4900", "4920", "4930", "4940", "4950", "4965") ~ "57",
CensusOcc %in% c("5000") ~ "58",
CensusOcc %in% c("5010", "5020", "5040") ~ "59",
CensusOcc %in% c("5100", "5110", "5120", "5130", "5140", "5150", "5160", "5165") ~ "60",
CensusOcc %in% c("5200", "5210", "5220", "5230", "5240", "5250", "5260", "5300", "5310", "5320", "5330", "5340", "5350", "5360", "5400", "5410", "5420") ~ "61",
CensusOcc %in% c("5500", "5510", "5521", "5522", "5530", "5540", "5550", "5560", "5600", "5610", "5630") ~ "62",
CensusOcc %in% c("5710", "5720", "5730", "5740") ~ "63",
CensusOcc %in% c("5810", "5820", "5830", "5840", "5850", "5860", "5900", "5910", "5920", "5940") ~ "64",
CensusOcc %in% c("6005") ~ "65",
CensusOcc %in% c("6010", "6020", "6040", "6050") ~ "66",
CensusOcc %in% c("6115") ~ "67",
CensusOcc %in% c("6120", "6130") ~ "68",
CensusOcc %in% c("6200") ~ "69",
CensusOcc %in% c("6210", "6220", "6230", "6240", "6250", "6260", "6305", "6330", "6355", "6360", "6400", "6410", "6441", "6442", "6460", "6500", "6515", "6520", "6530", "6540") ~ "70",
CensusOcc %in% c("6600") ~ "71",
CensusOcc %in% c("6660", "6700", "6710", "6720", "6730", "6740", "6750", "6765") ~ "72",
CensusOcc %in% c("6800", "6821", "6825", "6835", "6850", "6920", "6950") ~ "73",
CensusOcc %in% c("7000") ~ "74",
CensusOcc %in% c("7010", "7020", "7030", "7040", "7050", "7100", "7110", "7120", "7130") ~ "75",
CensusOcc %in% c("7140", "7150", "7160", "7200", "7210", "7220", "7240", "7260") ~ "76",
CensusOcc %in% c("7300", "7315", "7320", "7330", "7340", "7350", "7360", "7410", "7420", "7430", "7440", "7510", "7520", "7540", "7550", "7560", "7610", "7640") ~ "77",
CensusOcc %in% c("7700") ~ "78",
CensusOcc %in% c("7710", "7720", "7730", "7740", "7750") ~ "79",
CensusOcc %in% c("7800", "7810", "7830", "7840", "7850", "7855") ~ "80",
CensusOcc %in% c("7905", "7925", "7950", "8000", "8025", "8030", "8040", "8060", "8100", "8130", "8140", "8225") ~ "81",
CensusOcc %in% c("8250", "8255", "8256") ~ "82",
CensusOcc %in% c("8300", "8310", "8320", "8335", "8350", "8365", "8450", "8465") ~ "83",
CensusOcc %in% c("8500", "8510", "8530", "8540", "8555") ~ "84",
CensusOcc %in% c("8600", "8610", "8620", "8630") ~ "85",
CensusOcc %in% c("8640", "8650", "8710", "8720", "8730", "8740", "8750", "8760", "8800", "8810", "8830", "8850", "8910", "8920", "8930", "8940", "8950", "8865", "8990") ~ "86",
CensusOcc %in% c("9005") ~ "87",
CensusOcc %in% c("9030", "9040", "9050") ~ "88",
CensusOcc %in% c("9110", "9121", "9122", "9130", "9141", "9142", "9150") ~ "89",
CensusOcc %in% c("9210", "9240", "9265") ~ "90",
CensusOcc %in% c("9300", "9310", "9330") ~ "91",
CensusOcc %in% c("9350", "9365", "9410", "9415", "9430") ~ "92",
CensusOcc %in% c("9510", "9570", "9600", "9610", "9620", "9630", "9640", "9645", "9650", "9720", "9760") ~ "93",
CensusOcc %in% c("9830", "9840", "9850") ~ "94",
CensusOcc %in% c("9010", "9020", "9070", "9060", "9100", "9900") ~ "95",
TRUE ~ "00"))
#------------------------------------------------------------------------------------------------------------------------
#For Census codes, switch NIOSH military with:
# occ_detailed %in% "23" ~ "23 Census: Military Specific Occupations",
#And add:
# occ_detailed %in% "97" ~ "97 Census: Refused, Classified",
# occ_detailed %in% "98" ~ "98 Census: Not Ascertained",
# occ_detailed %in% "99" ~ "99 Census: Do not know",
#----------------------------------------------------------------------------------------------------------------------
#*2007/2012 4-DIGIT NAICS-BASED CENSUS INDUSTRY CODES RECODED TO 2018 NHIS DETAILED RECODES FOR INDUSTRY =IND_detailed
#INCLUDES CODES FOR 2007 SINCE THERE WAS A ONE-TO-ONE MATCH FOR CENSUS INDUSTRY CODES: SEE
# HTTPS://WWW.CENSUS.GOV/TOPICS/EMPLOYMENT/INDUSTRY-OCCUPATION/GUIDANCE/CODE-LISTS.HTML
#INCLUDES INDUSTRY CODE 2780 Metal forgings and stampings, WHICH WAS IN THE DETAILED RECODE BUT NOT THE SIMPLE
iotable <- iotable %>%
mutate(ind_detailed = case_when(
CensusInd %in% c("0170") ~ "01",
CensusInd %in% c("0180") ~ "02",
CensusInd %in% c("0190", "0270") ~ "03",
CensusInd %in% c("0280") ~ "04",
CensusInd %in% c("0290") ~ "05",
CensusInd %in% c("0370") ~ "06",
CensusInd %in% c("0380", "0390", "0470", "0480") ~ "07",
CensusInd %in% c("0490") ~ "08",
CensusInd %in% c("0570", "0580", "0590", "0670", "0680", "0690") ~ "09",
CensusInd %in% c("0770") ~ "10",
CensusInd %in% c("1070", "1080", "1090", "1170", "1180", "1190", "1270", "1280", "1290") ~ "11",
CensusInd %in% c("1370", "1390") ~ "12",
CensusInd %in% c("1470", "1480", "1490") ~ "13",
CensusInd %in% c("1570", "1590", "1670") ~ "14",
CensusInd %in% c("1691", "1770") ~ "15",
CensusInd %in% c("1790") ~ "16",
CensusInd %in% c("3770", "3780", "3790", "3875") ~ "17",
CensusInd %in% c("1870", "1880", "1890") ~ "18",
CensusInd %in% c("1990") ~ "19",
CensusInd %in% c("2070", "2090") ~ "20",
CensusInd %in% c("2170", "2180", "2190", "2270", "2280", "2290") ~ "21",
CensusInd %in% c("2370", "2380", "2390") ~ "22",
CensusInd %in% c("2470", "2480", "2490", "2570", "2590") ~ "23",
CensusInd %in% c("2670", "2680", "2690", "2770", "2780", "2990") ~ "24",
CensusInd %in% c("2790", "2870", "2880", "2890", "2970", "2980") ~ "25",
CensusInd %in% c("3070", "3080", "3095", "3170", "3180", "3291") ~ "26",
CensusInd %in% c("3365", "3370", "3380", "3390") ~ "27",
CensusInd %in% c("3470", "3490") ~ "28",
CensusInd %in% c("3570", "3580", "3590", "3670", "3680", "3690") ~ "29",
CensusInd %in% c("3895") ~ "30",
CensusInd %in% c("3960", "3970", "3980", "3990") ~ "31",
CensusInd %in% c("4070", "4080", "4090", "4170", "4180", "4195", "4265", "4270", "4280", "4290") ~ "32",
CensusInd %in% c("4370", "4380", "4390", "4470", "4480", "4490", "4560", "4570", "4580", "4585") ~ "33",
CensusInd %in% c("4590") ~ "34",
CensusInd %in% c("4670", "4680", "4690") ~ "35",
CensusInd %in% c("4770") ~ "36",
CensusInd %in% c("4780", "4795") ~ "37",
CensusInd %in% c("4870", "4880", "4890") ~ "38",
CensusInd %in% c("4971", "4972", "4980", "4990") ~ "39",
CensusInd %in% c("5070", "5080") ~ "40",
CensusInd %in% c("5090") ~ "41",
CensusInd %in% c("5170", "5180", "5190") ~ "42",
CensusInd %in% c("5275", "5280", "5295", "5370") ~ "43",
CensusInd %in% c("5381", "5391") ~ "44",
CensusInd %in% c("5470", "5480", "5490", "5570", "5580") ~ "45",
CensusInd %in% c("5593", "5670", "5680", "5690", "5790") ~ "46",
CensusInd %in% c("6070", "6080", "6090", "6170", "6180", "6190", "6270", "6280", "6290") ~ "47",
CensusInd %in% c("6370", "6380") ~ "48",
CensusInd %in% c("6390") ~ "49",
CensusInd %in% c("6470", "6480", "6490") ~ "50",
CensusInd %in% c("6570", "6590") ~ "51",
CensusInd %in% c("6670", "6680", "6690") ~ "52",
CensusInd %in% c("6672", "6695", "6770", "6780") ~ "53",
CensusInd %in% c("6870") ~ "54",
CensusInd %in% c("6880", "6890") ~ "55",
CensusInd %in% c("6970") ~ "56",
CensusInd %in% c("6991", "6992") ~ "57",
CensusInd %in% c("7071", "7072") ~ "58",
CensusInd %in% c("7080", "7181") ~ "59",
CensusInd %in% c("7190") ~ "60",
CensusInd %in% c("7270", "7280", "7290", "7370", "7380", "7390", "7460", "7470", "7480", "7490") ~ "61",
CensusInd %in% c("7570") ~ "62",
CensusInd %in% c("7580", "7590", "7670", "7680", "7690", "7770", "7780", "7790") ~ "63",
CensusInd %in% c("7860", "7870", "7880", "7890") ~ "64",
CensusInd %in% c("7970","7980", "7990", "8070", "8080", "8090", "8170", "8180") ~ "65",
CensusInd %in% c("8191", "8192") ~ "66",
CensusInd %in% c("8270", "8290") ~ "67",
CensusInd %in% c("8370", "8380", "8390", "8470") ~ "68",
CensusInd %in% c("8561", "8562", "8563", "8564") ~ "69",
CensusInd %in% c("8570") ~ "70",
CensusInd %in% c("8580", "8590") ~ "71",
CensusInd %in% c("8660", "8670") ~ "72",
CensusInd %in% c("8680", "8690") ~ "73",
CensusInd %in% c("8770", "8780", "8790", "8870", "8891") ~ "74",
CensusInd %in% c("8970", "8980", "8990", "9070", "9080", "9090") ~ "75",
CensusInd %in% c("9160", "9170", "9180", "9190") ~ "76",
CensusInd %in% c("9290") ~ "77",
CensusInd %in% c("9370", "9380", "9390", "9470", "9480", "9490", "9570", "9590") ~ "78",
CensusInd %in% c("9790", "9670", "9680", "9780", "9770", "9690", "9790") ~ "79",
CensusInd %in% c("9890", "9880", "9990") ~ "80",
TRUE ~ "00"))
#-------------------------------------------------------------------------------------------------------------------------
#Create recode industry titles
iotable <- iotable %>%
mutate(ind.names = case_when(
ind_detailed %in% "01" ~ "01 Crop production",
ind_detailed %in% "02" ~ "02 Animal production and aquaculture",
ind_detailed %in% "03" ~ "03 Forestry and logging",
ind_detailed %in% "04" ~ "04 Fishing, hunting, and trapping",
ind_detailed %in% "05" ~ "05 Support activities for agriculture and forestry",
ind_detailed %in% "06" ~ "06 Oil and gas extraction",
ind_detailed %in% "07" ~ "07 Mining (except oil and gas)",
ind_detailed %in% "08" ~ "08 Support activities for mining",
ind_detailed %in% "09" ~ "09 Utilities Industries",
ind_detailed %in% "10" ~ "10 Construction Industries",
ind_detailed %in% "11" ~ "11 Food manufacturing",
ind_detailed %in% "12" ~ "12 Beverage and tobacco product manufacturing",
ind_detailed %in% "13" ~ "13 Textile mills",
ind_detailed %in% "14" ~ "14 Textile product mills",
ind_detailed %in% "15" ~ "15 Apparel manufacturing",
ind_detailed %in% "16" ~ "16 Leather and allied product manufacturing",
ind_detailed %in% "17" ~ "17 Wood product manufacturing",
ind_detailed %in% "18" ~ "18 Paper manufacturing",
ind_detailed %in% "19" ~ "19 Printing and related support activities",
ind_detailed %in% "20" ~ "20 Petroleum and coal products manufacturing",
ind_detailed %in% "21" ~ "21 Chemical manufacturing",
ind_detailed %in% "22" ~ "22 Plastics and rubber products manufacturing",
ind_detailed %in% "23" ~ "23 Nonmetallic mineral product manufacturing",
ind_detailed %in% "24" ~ "24 Primary metal manufacturing",
ind_detailed %in% "25" ~ "25 Fabricated metal product manufacturing",
ind_detailed %in% "26" ~ "26 Machinery manufacturing",
ind_detailed %in% "27" ~ "27 Computer and electronic product manufacturing",
ind_detailed %in% "28" ~ "28 Electrical equipment, appliance, and component manufacturing",
ind_detailed %in% "29" ~ "29 Transportation equipment manufacturing",
ind_detailed %in% "30" ~ "30 Furniture and related product manufacturing",
ind_detailed %in% "31" ~ "31 Miscellaneous manufacturing",
ind_detailed %in% "32" ~ "32 Merchant wholesalers, durable goods",
ind_detailed %in% "33" ~ "33 Merchant wholesalers, nondurable goods",
ind_detailed %in% "34" ~ "34 Non-specified wholesale trade",
ind_detailed %in% "35" ~ "35 Motor vehicle and parts dealers",
ind_detailed %in% "36" ~ "36 Furniture and home furnishings stores",
ind_detailed %in% "37" ~ "37 Electronics and appliance stores",
ind_detailed %in% "38" ~ "38 Building material and garden equipment and supplies dealers",
ind_detailed %in% "39" ~ "39 Food and beverage stores",
ind_detailed %in% "40" ~ "40 Health and personal care stores",
ind_detailed %in% "41" ~ "41 Gasoline stations",
ind_detailed %in% "42" ~ "42 Clothing, shoe, jewelry, luggage, and leather goods stores",
ind_detailed %in% "43" ~ "43 Sporting goods, camera, hobby, book and music stores",
ind_detailed %in% "44" ~ "44 General merchandise stores",
ind_detailed %in% "45" ~ "45 Miscellaneous store retailers",
ind_detailed %in% "46" ~ "46 Nonstore retailers and non-specified retail trade",
ind_detailed %in% "47" ~ "47 Transportation (including support activities for transportation)",
ind_detailed %in% "48" ~ "48 Postal service, couriers, and messengers",
ind_detailed %in% "49" ~ "49 Warehousing and storage",
ind_detailed %in% "50" ~ "50 Newspaper, periodical, book, and software publishing industries",
ind_detailed %in% "51" ~ "51 Motion picture, video, and sound recording industries",
ind_detailed %in% "52" ~ "52 Broadcasting and telecommunications",
ind_detailed %in% "53" ~ "53 Libraries and archives, internet publishing, web search portals, data processing and hosting services, and other information services",
ind_detailed %in% "54" ~ "54 Monetary authorities -- central bank",
ind_detailed %in% "55" ~ "55 Credit intermediation and related activities",
ind_detailed %in% "56" ~ "56 Securities, commodity contracts, and other financial investments and related activities",
ind_detailed %in% "57" ~ "57 Insurance carriers and related activities",
ind_detailed %in% "58" ~ "58 Real estate",
ind_detailed %in% "59" ~ "59 Automotive and other consumer goods rental and leasing services",
ind_detailed %in% "60" ~ "60 Commercial, industrial, and other intangible assets (except copyrighted works)",
ind_detailed %in% "61" ~ "61 Professional, Scientific, and Technical Services Industries",
ind_detailed %in% "62" ~ "62 Management of Companies and Enterprises Industries",
ind_detailed %in% "63" ~ "63 Administrative and Support and Waste Management and Remediation Services Industries",
ind_detailed %in% "64" ~ "64 Education Services Industries",
ind_detailed %in% "65" ~ "65 Ambulatory health care services",
ind_detailed %in% "66" ~ "66 Hospitals",
ind_detailed %in% "67" ~ "67 Nursing and residential care facilities",
ind_detailed %in% "68" ~ "68 Social assistance",
ind_detailed %in% "69" ~ "69 Performing arts, spectator sports, promoters, agents, artists, writers and related industries",
ind_detailed %in% "70" ~ "70 Museums, historical sites, and similar institutions",
ind_detailed %in% "71" ~ "71 Amusement, gambling, and recreation industries",
ind_detailed %in% "72" ~ "72 Accommodation",
ind_detailed %in% "73" ~ "73 Food services and drinking places",
ind_detailed %in% "74" ~ "74 Repair and maintenance",
ind_detailed %in% "75" ~ "75 Personal services (barber shops, beauty salons, nail salons, laundry, funeral homes and cemeteries)",
ind_detailed %in% "76" ~ "76 Religious, grantmaking, civic, labor, professional, and similar organizations",
ind_detailed %in% "77" ~ "77 Private households",
ind_detailed %in% "78" ~ "78 Public Administration Industries",
ind_detailed %in% "79" ~ "79 NIOSH NCHS military",
ind_detailed %in% "80" ~ "80 NIOSH NCHS Other--Misc",
TRUE ~ "00"))
#------------------------------------------------------------------------------------------------------------------------
#For Census code, switch NIOSH NCHS Military code for:
# ind_detailed %in% "21" ~ "21 Census Military",
#And add:
# ind_detailed %in% "97" ~ "97 CENSUS REFUSED CLASSIFIED",
# ind_detailed %in% "98" ~ "98 CENSUS NOT ASCERTAINED",
# ind_detailed %in% "99" ~ "99 CENSUS NOT ASCERTAINED",
#------------------------------------------------------------------------------------------------------------------------
#Output
#Check for number of codes that were not categorized into detailed categories
#Are there any missing values that missed the recode?
sum(is.na(iotable$occ.names))
sum(is.na(iotable$ind.names))
#Are there any values that were uncategorized based on our recode?
sum(iotable$occ.names == "00")
sum(iotable$ind.names == "00")
#Table for count and percentage of Occupation and Industry categories
freq(iotable$occ.names, cumul=FALSE, weights= NA, display.type = FALSE, report.nas = TRUE)
freq(iotable$ind.names, cumul=FALSE, weights= NA, display.type = FALSE, report.nas = TRUE)
#Optional: Find raw data values of any missing categories. If values are wrong, this table will show you which so you can fix or add them.
# subset <- iotable %>% filter(iotable$occ_detailed == "00")
# freq(subset$CensusOcc)
# subset <- iotable %>% filter(iotable$ind_detailed == "00")
# freq(subset$CensusInd)