Skip to content

Commit ed9fa83

Browse files
authored
Merge pull request #344 from USEPA/waste_disagg_update
Adds Detail waste disaggregation for 2017 schema
2 parents b140619 + d1c7b1c commit ed9fa83

9 files changed

+517
-8
lines changed

R/DisaggregateFunctions.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ disaggregateSetup <- function (model, configpaths = NULL, setupType = "Disaggreg
132132
sep = ",", header = TRUE,
133133
stringsAsFactors = FALSE,
134134
check.names = FALSE)
135+
colnames(spec$NAICSSectorCW)[which(
136+
names(spec$NAICSSectorCW) %in% c("NAICS_2012_Code", "NAICS_2017_Code"))] <- "NAICS_Code"
135137

136138
newNames <- unique(data.frame("SectorCode" = spec$NAICSSectorCW$USEEIO_Code,
137139
"SectorName" = spec$NAICSSectorCW$USEEIO_Name,
@@ -647,9 +649,9 @@ disaggregateSatelliteSubsetByRatio <- function(sattable, disagg, allocating_sect
647649
disaggregateSatelliteTable <- function (disagg, tbs, sat_spec) {
648650
sattable <- tbs
649651
# identify NAICS that require further disaggregation
650-
naics <- disagg$NAICSSectorCW[c('NAICS_2012_Code','USEEIO_Code')]
651-
codes <- unique(naics[duplicated(naics$NAICS_2012_Code),]$NAICS_2012_Code)
652-
naics <- naics[which(naics$NAICS_2012_Code %in% codes),]
652+
naics <- disagg$NAICSSectorCW[c('NAICS_Code','USEEIO_Code')]
653+
codes <- unique(naics[duplicated(naics$NAICS_Code),]$NAICS_Code)
654+
naics <- naics[which(naics$NAICS_Code %in% codes),]
653655

654656
original_code <- gsub("/.*", "", disagg$OriginalSectorCode)
655657
codes <- c(original_code, codes)
@@ -1030,13 +1032,13 @@ disaggregateMasterCrosswalk <- function (model, disagg){
10301032
# used to determine the length of the sector codes. E.g., detail would be 6, while summary would generally
10311033
# be 3 though variable, and sector would be variable
10321034
secLength <- regexpr(pattern ='/',disagg$OriginalSectorCode) - 1
1033-
cw <- disagg$NAICSSectorCW[, c('NAICS_2012_Code','USEEIO_Code')]
1035+
cw <- disagg$NAICSSectorCW[, c('NAICS_Code','USEEIO_Code')]
10341036
# For all rows in the USEEIO_Code column, remove all characters after (and including) "/"
10351037
cw$USEEIO_Code <- sub("/.*","",cw$USEEIO_Code)
10361038

10371039
# Update original sector codes with disaggregated sector codes in the relevant column (i.e. cwColIndex)
10381040
# where rows have an exact match for the disaggregated codes in the NAICS column
1039-
new_cw <-merge(new_cw, cw, by.x=c("NAICS"), by.y=c("NAICS_2012_Code"), all=T)
1041+
new_cw <-merge(new_cw, cw, by.x=c("NAICS"), by.y=c("NAICS_Code"), all=T)
10401042

10411043
new_cw$USEEIO <- ifelse(is.na(new_cw$USEEIO_Code), new_cw$USEEIO, new_cw$USEEIO_Code)
10421044

@@ -1053,10 +1055,10 @@ disaggregateMasterCrosswalk <- function (model, disagg){
10531055
rowComparisons[1:length(disagg$NewSectorCodes)] <- TRUE
10541056
} else {
10551057
#compare the value in the first column (NAICS) to the NAICS values in the disaggCrosswalk. Result is a string with TRUE where first column is a substring of values in disaggCrosswalk
1056-
rowComparisons <- grepl(crosswalkRow$NAICS[1], disagg$NAICSSectorCW$NAICS_2012_Code)
1058+
rowComparisons <- grepl(crosswalkRow$NAICS[1], disagg$NAICSSectorCW$NAICS_Code)
10571059
}
10581060

1059-
rowReplacements <- disagg$NAICSSectorCW$NAICS_2012_Code[rowComparisons] #Get the NAICS sector codes in the disagg crosswalk that are a match for the NAICS substring in the master crosswalk
1061+
rowReplacements <- disagg$NAICSSectorCW$NAICS_Code[rowComparisons] #Get the NAICS sector codes in the disagg crosswalk that are a match for the NAICS substring in the master crosswalk
10601062
rowReplacements <- sub("/.*","",disagg$NAICSSectorCW$USEEIO_Code[rowComparisons]) #Get the disaggregated sector codes that are mapped to the matches of the NAICS substring
10611063
rowReplacements <- unique(rowReplacements) #reduce the list to the unique number of disaggregated sectors that the row comparisons map to
10621064

R/WIOFunctions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ addSectorsToWIOCW <- function (model, spec){
741741
WIONAICSSectorCW[,1] <- "WIO"
742742
WIONAICSSectorCW$Tag <- "USEEIO sectors as WIO Treatment sectors"
743743
WIONAICSSectorCW$Type <- "N/A"
744-
WIONAICSSectorCW$NAICS_2012_Code <- "N/A"
744+
WIONAICSSectorCW$NAICS_Code <- "N/A"
745745
WIONAICSSectorCW$Subcategory <- "N/A"
746746
WIONAICSSectorCW$Description <- "N/A"
747747

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Disaggregation:
2+
562000/US:
3+
OriginalSectorCode: "562000/US"
4+
OriginalSectorName: "Waste Management and remediation services"
5+
DisaggregationType: "Userdefined"
6+
SectorFile: WasteDisaggregation_Sectors.csv
7+
MakeFile: WasteDisaggregationDetail2017_Make.csv
8+
UseFile: WasteDisaggregationDetail2017_Use.csv
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
IndustryCode,CommodityCode,PercentMake,Note
2+
562000/US,562111/US,4.79E-01,Make column sum
3+
562000/US,562HAZ/US,1.28E-01,Make column sum
4+
562000/US,562212/US,8.12E-02,Make column sum
5+
562000/US,562213/US,1.36E-02,Make column sum
6+
562000/US,562910/US,1.47E-01,Make column sum
7+
562000/US,562920/US,5.40E-02,Make column sum
8+
562000/US,562OTH/US,9.78E-02,Make column sum
9+
562111/US,562111/US,4.23E-01,Make table intersection
10+
562HAZ/US,562HAZ/US,1.50E-01,Make table intersection
11+
562212/US,562212/US,7.87E-02,Make table intersection
12+
562213/US,562213/US,1.31E-02,Make table intersection
13+
562910/US,562910/US,1.68E-01,Make table intersection
14+
562920/US,562920/US,5.23E-02,Make table intersection
15+
562OTH/US,562OTH/US,1.15E-01,Make table intersection
16+
221300/US,562111/US,7.63E-01,commodity disaggregation
17+
221300/US,562212/US,1.29E-01,commodity disaggregation
18+
221300/US,562213/US,2.16E-02,commodity disaggregation
19+
221300/US,562920/US,8.61E-02,commodity disaggregation
20+
484000/US,562111/US,1.00E+00,commodity disaggregation
21+
511110/US,562111/US,1.00E+00,commodity disaggregation
22+
561700/US,562910/US,1.00E+00,commodity disaggregation
23+
GSLGO/US,562111/US,7.63E-01,commodity disaggregation
24+
GSLGO/US,562212/US,1.29E-01,commodity disaggregation
25+
GSLGO/US,562213/US,2.16E-02,commodity disaggregation
26+
GSLGO/US,562920/US,8.61E-02,commodity disaggregation
27+
562212/US,211000/US,1.00E+00,industry disaggregation
28+
562111/US,2332D0/US,4.31E-01,industry disaggregation
29+
562HAZ/US,2332D0/US,1.94E-01,industry disaggregation
30+
562212/US,2332D0/US,8.19E-02,industry disaggregation
31+
562213/US,2332D0/US,1.36E-02,industry disaggregation
32+
562910/US,2332D0/US,1.51E-01,industry disaggregation
33+
562920/US,2332D0/US,4.06E-02,industry disaggregation
34+
562OTH/US,2332D0/US,8.85E-02,industry disaggregation
35+
562111/US,444000/US,4.31E-01,industry disaggregation
36+
562HAZ/US,444000/US,1.94E-01,industry disaggregation
37+
562212/US,444000/US,8.19E-02,industry disaggregation
38+
562213/US,444000/US,1.36E-02,industry disaggregation
39+
562910/US,444000/US,1.51E-01,industry disaggregation
40+
562920/US,444000/US,4.06E-02,industry disaggregation
41+
562OTH/US,444000/US,8.85E-02,industry disaggregation
42+
562111/US,48A000/US,4.31E-01,industry disaggregation
43+
562HAZ/US,48A000/US,1.94E-01,industry disaggregation
44+
562212/US,48A000/US,8.19E-02,industry disaggregation
45+
562213/US,48A000/US,1.36E-02,industry disaggregation
46+
562910/US,48A000/US,1.51E-01,industry disaggregation
47+
562920/US,48A000/US,4.06E-02,industry disaggregation
48+
562OTH/US,48A000/US,8.85E-02,industry disaggregation
49+
562111/US,532400/US,4.31E-01,industry disaggregation
50+
562HAZ/US,532400/US,1.94E-01,industry disaggregation
51+
562212/US,532400/US,8.19E-02,industry disaggregation
52+
562213/US,532400/US,1.36E-02,industry disaggregation
53+
562910/US,532400/US,1.51E-01,industry disaggregation
54+
562920/US,532400/US,4.06E-02,industry disaggregation
55+
562OTH/US,532400/US,8.85E-02,industry disaggregation
56+
562111/US,541511/US,4.31E-01,industry disaggregation
57+
562HAZ/US,541511/US,1.94E-01,industry disaggregation
58+
562212/US,541511/US,8.19E-02,industry disaggregation
59+
562213/US,541511/US,1.36E-02,industry disaggregation
60+
562910/US,541511/US,1.51E-01,industry disaggregation
61+
562920/US,541511/US,4.06E-02,industry disaggregation
62+
562OTH/US,541511/US,8.85E-02,industry disaggregation
63+
562111/US,5416A0/US,4.31E-01,industry disaggregation
64+
562HAZ/US,5416A0/US,1.94E-01,industry disaggregation
65+
562212/US,5416A0/US,8.19E-02,industry disaggregation
66+
562213/US,5416A0/US,1.36E-02,industry disaggregation
67+
562910/US,5416A0/US,1.51E-01,industry disaggregation
68+
562920/US,5416A0/US,4.06E-02,industry disaggregation
69+
562OTH/US,5416A0/US,8.85E-02,industry disaggregation
70+
562111/US,541700/US,4.31E-01,industry disaggregation
71+
562HAZ/US,541700/US,1.94E-01,industry disaggregation
72+
562212/US,541700/US,8.19E-02,industry disaggregation
73+
562213/US,541700/US,1.36E-02,industry disaggregation
74+
562910/US,541700/US,1.51E-01,industry disaggregation
75+
562920/US,541700/US,4.06E-02,industry disaggregation
76+
562OTH/US,541700/US,8.85E-02,industry disaggregation
77+
562920/US,S00401/US,1.00E+00,industry disaggregation

0 commit comments

Comments
 (0)