-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeSlicedNAICSs.R
59 lines (51 loc) · 2.1 KB
/
makeSlicedNAICSs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# title: "makeSlicedNAICSs.R"
# author: "Eric Koski"
# date: "12/10/2019"
# Copyright (c) 2021 Orebed Analytics LLC under MIT License; see LICENSE.md.
#
# Data files produced by this software are licensed under a Creative Commons
# Attribution 4.0 International License; see
# https://creativecommons.org/licenses/by/4.0/.
NAICS_Descriptions_2017 <- NAICS_Descriptions_2017 %>%
filter(!is.na(NAICS)) %>%
bind_rows(NAICS_Addrows1dig) %>%
bind_rows(NAICS_Addrows2dig) %>%
bind_rows(NAICS_Addrows3dig) %>%
bind_rows(NAICS_Addrows4dig) %>%
arrange(as.character(NAICS))
# Add columns with NAICS code values trimmed to max 1, 2, or 3 digits
NAICS_Descriptions_2017 <- NAICS_Descriptions_2017 %>%
mutate(NAICS1dig = trimInt(NAICS, 1)) %>%
mutate(NAICS2dig = trimInt(NAICS, 2)) %>%
mutate(NAICS3dig = trimInt(NAICS, 3)) %>%
mutate(NAICS4dig = trimInt(NAICS, 4))
# In what follows we drop the descriptions, since they're bulky
# Make a table of the one-digit abbreviated NAICS codes
NAICS_Descriptions1dig <- NAICS_Descriptions_2017 %>%
filter(NAICS == NAICS1dig) %>%
transmute(NAICS1dig = NAICS1dig, NAICSname1dig = NAICSname) %>%
arrange(NAICS1dig) %>%
distinct()
# Make a table of the two-digit abbreviated NAICS codes
NAICS_Descriptions2dig <- NAICS_Descriptions_2017 %>%
filter(NAICS == NAICS2dig) %>%
filter(str_length(as.character(NAICS)) == 2) %>%
transmute(NAICS2dig = NAICS2dig, NAICSname2dig = NAICSname) %>%
arrange(NAICS2dig) %>%
distinct()
# Make an analogous table of 3-digit abbreviated NAICS codes
NAICS_Descriptions3dig <- NAICS_Descriptions_2017 %>%
filter(NAICS == NAICS3dig) %>%
filter(str_length(as.character(NAICS)) == 3) %>%
transmute(NAICS3dig = NAICS3dig,
NAICSname3dig = NAICSname) %>%
arrange(NAICS3dig) %>%
distinct()
# Make an analogous table of 4-digit abbreviated NAICS codes
NAICS_Descriptions4dig <- NAICS_Descriptions_2017 %>%
filter(NAICS == NAICS4dig) %>%
filter(str_length(as.character(NAICS)) == 4) %>%
transmute(NAICS4dig = NAICS4dig,
NAICSname4dig = NAICSname) %>%
arrange(NAICS4dig) %>%
distinct()