#------------------------------------------------------------------------------------------------------------------------ #FOR PROBLEMS OR QUESTIONS ABOUT THIS CODE, PLEASE EMAIL: noms@cdc.gov #2010 4-digit census occupation codes (from 2010 soc) recoded to 2018 nhis detailed recodes for occupation =occ_detailed #2007/2012 4-digit naics-based census industry codes recoded to 2018 nhis detailed recodes for industry =ind_detailed #caution: 2018 census codes used in the current American community survey have 146 new codes for occupation and 19 new industry codes. these new codes are not included in this program. #based on recodes from industry & occupation appendices in this document ftp://ftp.cdc.gov/pub/health_statistics/nchs/dataset_documentation/nhis/2018/samadult_layout.pdf #niosh nchs codes are those assigned by the niosh industry and occupation computerized coding system (nioccs)for non-paid workers and military #see https://www.cdc.gov/niosh/topics/coding/nioccsuserdocumentation.html #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: # https://www.cdc.gov/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","0050","0060") ~ "02", CensusOcc %in% c("0100","0110","0120","0135","0136","0137","0140","0150","0160") ~ "03", CensusOcc %in% c("0205","0220","0230","0300","0310","0325","0330","0340","0350","0360","0400","0410","0420","0425","0430") ~ "04", CensusOcc %in% c("0500","0510","0520","0530","0540","0565","0600","0630","0640","0650","0700","0710","0725","0726","0735","0740") ~ "05", CensusOcc %in% c("0800","0810","0820","0830","0840","0850","0860","0900","0910","0930","0940","0950") ~ "06", CensusOcc %in% c("1005","1006","1007","1010","1020","1030","1050","1060","1105","1106","1107") ~ "07", CensusOcc %in% c("1200","1210","1220","1230","1240") ~ "08", CensusOcc %in% c("1300","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("1540","1550","1560") ~ "11", CensusOcc %in% c("1600","1610","1640","1650","1660") ~ "12", CensusOcc %in% c("1700","1710","1720","1740","1760") ~ "13", CensusOcc %in% c("1800","1815","1820","1830","1840","1860") ~ "14", CensusOcc %in% c("1900","1910","1920","1930","1940","1950","1965") ~ "15", CensusOcc %in% c("2000","2010","2015","2016","2025") ~ "16", CensusOcc %in% c("2040","2050","2060") ~ "17", CensusOcc %in% c("2100","2105","2110") ~ "18", CensusOcc %in% c("2145","2160") ~ "19", CensusOcc %in% c("2200") ~ "20", CensusOcc %in% c("2300","2310","2320","2330") ~ "21", CensusOcc %in% c("2340") ~ "22", CensusOcc %in% c("2400","2430","2440") ~ "23", CensusOcc %in% c("2540","2550") ~ "24", CensusOcc %in% c("2600","2630") ~ "25", CensusOcc %in% c("2700","2710","2720","2740","2750","2760") ~ "26", CensusOcc %in% c("2800","2810","2825","2830","2840","2850","2860") ~ "27", CensusOcc %in% c("2900","2910","2920","2960") ~ "28", CensusOcc %in% c("3000","3010","3030","3040","3050","3060","3110","3120","3140","3150","3160","3200","3210","3220","3230","3235","3245","3250","3255","3256","3257","3258","3260") ~ "29", CensusOcc %in% c("3300","3310","3320","3400","3420","3500","3510","3520","3535") ~ "30", CensusOcc %in% c("3540") ~ "31", CensusOcc %in% c("3600") ~ "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","3730") ~ "35", CensusOcc %in% c("3740","3750") ~ "36", CensusOcc %in% c("3800","3820","3830","3840","3850","3860") ~ "37", CensusOcc %in% c("3900","3910","3930","3940","3945","3955") ~ "38", CensusOcc %in% c("4000","4010") ~ "39", CensusOcc %in% c("4020","4030") ~ "40", CensusOcc %in% c("4040","4050","4060","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("4250") ~ "45", CensusOcc %in% c("4300","4320") ~ "46", CensusOcc %in% c("4340","4350") ~ "47", CensusOcc %in% c("4400","4410","4420","4430") ~ "48", CensusOcc %in% c("4460","4465") ~ "49", CensusOcc %in% c("4500","4510","4520") ~ "50", CensusOcc %in% c("4530","4540") ~ "51", CensusOcc %in% c("4600","4610","4620","4640","4650") ~ "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","5030") ~ "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","5520","5530","5540","5550","5560","5600","5610","5620","5630") ~ "62", CensusOcc %in% c("5700") ~ "63", CensusOcc %in% c("5800","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("6100","6110") ~ "67", CensusOcc %in% c("6120","6130") ~ "68", CensusOcc %in% c("6200") ~ "69", CensusOcc %in% c("6210","6220","6230","6240","6250","6260","6300","6310","6320","6330","6355","6360","6400","6420","6430","6440","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","6820","6830","6840","6910","6920","6930","6940") ~ "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","7600","7610","7630") ~ "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("7900","7920","7930","7940","7950","7960","8000","8010","8020","8030","8040","8060","8100","8120","8130","8140","8150","8160","8200","8210","8220") ~ "81", CensusOcc %in% c("8250","8255","8256") ~ "82", CensusOcc %in% c("8300","8310","8320","8330","8340","8350","8360","8400","8410","8420","8430","8440","8450","8460") ~ "83", CensusOcc %in% c("8500","8510","8520","8530","8540","8550") ~ "84", CensusOcc %in% c("8600","8610","8620","8630") ~ "85", CensusOcc %in% c("8640","8650","8710","8720","8730","8740","8750","8760","8800","8810","8830","8840","8850","8860","8900","8910","8920","8930","8940","8950","8965") ~ "86", CensusOcc %in% c("9000") ~ "87", CensusOcc %in% c("9030","9040","9050") ~ "88", CensusOcc %in% c("9110","9120","9130","9140","9150") ~ "89", CensusOcc %in% c("9200","9230","9240","9260") ~ "90", CensusOcc %in% c("9300","9310","9330") ~ "91", CensusOcc %in% c("9340","9350","9360","9410","9415","9420") ~ "92", CensusOcc %in% c("9500","9510","9520","9560","9600","9610","9620","9630","9640","9650","9720","9730","9740","9750") ~ "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( occ_detailed %in% "01" ~ "01 Chief executives; general and operations managers; legislators", occ_detailed %in% "02" ~ "02 Advertising, marketing, promotions, public relations, and sales managers", occ_detailed %in% "03" ~ "03 Operations specialties managers", occ_detailed %in% "04" ~ "04 Other management occupations", occ_detailed %in% "05" ~ "05 Business operations specialists", occ_detailed %in% "06" ~ "06 Financial specialists", occ_detailed %in% "07" ~ "07 Computer specialists", occ_detailed %in% "08" ~ "08 Mathematical science occupations", occ_detailed %in% "09" ~ "09 Architects, surveyors, and cartographers", occ_detailed %in% "10" ~ "10 Engineers", occ_detailed %in% "11" ~ "11 Drafters, engineering, and mapping technicians", occ_detailed %in% "12" ~ "12 Life scientists", occ_detailed %in% "13" ~ "13 Physical scientists", occ_detailed %in% "14" ~ "14 Social scientists and related workers", occ_detailed %in% "15" ~ "15 Life, physical, and social science technicians", occ_detailed %in% "16" ~ "16 Counselors, social workers, and other community and social service specialists", occ_detailed %in% "17" ~ "17 Religious workers", occ_detailed %in% "18" ~ "18 Lawyers, judges and related workers", occ_detailed %in% "19" ~ "19 Legal support workers", occ_detailed %in% "20" ~ "20 Postsecondary teachers", occ_detailed %in% "21" ~ "21 Primary, secondary, and special education school teachers", occ_detailed %in% "22" ~ "22 Other teachers and instructors", occ_detailed %in% "23" ~ "23 Librarians, curators, and archivists", occ_detailed %in% "24" ~ "24 Other education, training, and library occupations", occ_detailed %in% "25" ~ "25 Art and design workers", occ_detailed %in% "26" ~ "26 Entertainers and performers, sports and related workers", occ_detailed %in% "27" ~ "27 Media and communications workers", occ_detailed %in% "28" ~ "28 Media and communications equipment workers", occ_detailed %in% "29" ~ "29 Health diagnosing and treating practitioners", occ_detailed %in% "30" ~ "30 Health technologists and technicians", occ_detailed %in% "31" ~ "31 Other healthcare practitioners and technical occupations", occ_detailed %in% "32" ~ "32 Nursing, psychiatric, and home health aides", occ_detailed %in% "33" ~ "33 Occupational and physical therapist assistants and aides", occ_detailed %in% "34" ~ "34 Other healthcare support occupations", occ_detailed %in% "35" ~ "35 First-line supervisors/managers, protective service workers", occ_detailed %in% "36" ~ "36 Fire fighting and preventions workers", occ_detailed %in% "37" ~ "37 Law enforcement workers", occ_detailed %in% "38" ~ "38 Other protective service workers", occ_detailed %in% "39" ~ "39 Supervisors, food preparation, and service worker", occ_detailed %in% "40" ~ "40 Cooks and food preparation workers", occ_detailed %in% "41" ~ "41 Food and beverage serving workers", occ_detailed %in% "42" ~ "42 Other food preparation and serving related workers", occ_detailed %in% "43" ~ "43 Supervisors, building and grounds cleaning and maintenance workers", occ_detailed %in% "44" ~ "44 Building cleaning and pest control workers", occ_detailed %in% "45" ~ "45 Grounds maintenance workers", occ_detailed %in% "46" ~ "46 Supervisors, personal care and service workers", occ_detailed %in% "47" ~ "47 Animal care and service workers", occ_detailed %in% "48" ~ "48 Entertainment attendants and related workers", occ_detailed %in% "49" ~ "49 Funeral service workers", occ_detailed %in% "50" ~ "50 Personal appearance workers", occ_detailed %in% "51" ~ "51 Transportation, tourism, and lodging attendants", occ_detailed %in% "52" ~ "52 Other personal care and service workers", occ_detailed %in% "53" ~ "53 Supervisors, sales workers", occ_detailed %in% "54" ~ "54 Retail sales workers", occ_detailed %in% "55" ~ "55 Sales representatives, services", occ_detailed %in% "56" ~ "56 Sales representatives, wholesale and manufacturing", occ_detailed %in% "57" ~ "57 Other sales and related workers", occ_detailed %in% "58" ~ "58 Supervisors, office and administrative support workers", occ_detailed %in% "59" ~ "59 Communications equipment operators", occ_detailed %in% "60" ~ "60 Financial clerks", occ_detailed %in% "61" ~ "61 Information and record clerks", occ_detailed %in% "62" ~ "62 Material recording, scheduling, dispatching, and distributing workers", occ_detailed %in% "63" ~ "63 Secretaries and administrative assistants ", occ_detailed %in% "64" ~ "64 Other office and administrative support workers", occ_detailed %in% "65" ~ "65 Supervisors, farming, fishing, and forestry workers", occ_detailed %in% "66" ~ "66 Agricultural workers", occ_detailed %in% "67" ~ "67 Fishing and hunting workers", occ_detailed %in% "68" ~ "68 Forest, conservation, and logging workers", occ_detailed %in% "69" ~ "69 Supervisors, construction and extraction workers", occ_detailed %in% "70" ~ "70 Construction trades workers", occ_detailed %in% "71" ~ "71 Helpers, construction trades", occ_detailed %in% "72" ~ "72 Other construction and related workers", occ_detailed %in% "73" ~ "73 Extraction workers", occ_detailed %in% "74" ~ "74 Supervisors of installation, maintenance, and repair workers", occ_detailed %in% "75" ~ "75 Electrical and electronic equipment mechanics, installers, and repairers", occ_detailed %in% "76" ~ "76 Vehicle and mobile equipment mechanics, installers, and repairers", occ_detailed %in% "77" ~ "77 Other installation, maintenance, and repair occupations", occ_detailed %in% "78" ~ "78 Supervisors, production workers", occ_detailed %in% "79" ~ "79 Assemblers and fabricators", occ_detailed %in% "80" ~ "80 Food processing workers", occ_detailed %in% "81" ~ "81 Metal workers and plastic workers", occ_detailed %in% "82" ~ "82 Printing workers", occ_detailed %in% "83" ~ "83 Textile, apparel, and furnishing workers", occ_detailed %in% "84" ~ "84 Woodworkers", occ_detailed %in% "85" ~ "85 Plant and system operators", occ_detailed %in% "86" ~ "86 Other production occupations", occ_detailed %in% "87" ~ "87 Supervisors, transportation and material moving workers", occ_detailed %in% "88" ~ "88 Air transportation workers", occ_detailed %in% "89" ~ "89 Motor vehicle operators", occ_detailed %in% "90" ~ "90 Rail transportation workers", occ_detailed %in% "91" ~ "91 Water transportation workers", occ_detailed %in% "92" ~ "92 Other transportation workers", occ_detailed %in% "93" ~ "93 Material moving workers", occ_detailed %in% "94" ~ "94 NIOSH NCHS military", occ_detailed %in% "95" ~ "95 NIOSH NCHS Other--Misc", 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("1680", "1690", "1770") ~ "15", CensusInd %in% c("1790") ~ "16", CensusInd %in% c("3770", "3780", "3790", "3870", "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", "3090", "3095", "3170", "3180", "3190", "3290") ~ "26", CensusInd %in% c("3360", "3365", "3370", "3380", "3390") ~ "27", CensusInd %in% c("3470", "3490") ~ "28", CensusInd %in% c("3570", "3580", "3590", "3670", "3680", "3690") ~ "29", CensusInd %in% c("3890", "3895") ~ "30", CensusInd %in% c("3960", "3970", "3980", "3990") ~ "31", CensusInd %in% c("4070", "4080", "4090", "4170", "4180", "4190", "4195", "4260", "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", "4790", "4795") ~ "37", CensusInd %in% c("4870", "4880", "4890") ~ "38", CensusInd %in% c("4970", "4980", "4990") ~ "39", CensusInd %in% c("5070", "5080") ~ "40", CensusInd %in% c("5090") ~ "41", CensusInd %in% c("5170", "5180", "5190") ~ "42", CensusInd %in% c("5270", "5275", "5280", "5290", "5295", "5370") ~ "43", CensusInd %in% c("5380", "5390") ~ "44", CensusInd %in% c("5470", "5480", "5490", "5570", "5580") ~ "45", CensusInd %in% c("5590", "5591", "5592", "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("6770", "6672", "6695", "6780") ~ "53", CensusInd %in% c("6870") ~ "54", CensusInd %in% c("6880", "6890") ~ "55", CensusInd %in% c("6970") ~ "56", CensusInd %in% c("6990") ~ "57", CensusInd %in% c("7070") ~ "58", CensusInd %in% c("7080", "7170", "7180") ~ "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("8190") ~ "66", CensusInd %in% c("8270", "8290") ~ "67", CensusInd %in% c("8370", "8380", "8390", "8470") ~ "68", CensusInd %in% c("8560") ~ "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", "8880", "8890") ~ "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", "9870") ~ "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", 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 non-metallic 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 and clothing accessories 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 Publishing industries (except internet)", ind_detailed %in% "51" ~ "51 Motion picture and sound recording industries", ind_detailed %in% "52" ~ "52 broadcasting and telecommunications", ind_detailed %in% "53" ~ "53 information services and data processing", 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 Rental and Leasing services", ind_detailed %in% "60" ~ "60 Lessors of nonfinancial 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", 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, 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)