Skip to content

Commit 1565a70

Browse files
authored
Merge pull request #346 from USEPA/release_v1.7.2
Release v1.7.2
2 parents b042a75 + d5d3561 commit 1565a70

21 files changed

+542
-30
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: useeior
22
Type: Package
33
Title: USEEIO R modeling software
4-
Version: 1.7.1
5-
Date: 2025-4-28
4+
Version: 1.7.2
5+
Date: 2025-7-28
66
Authors@R: c(
77
person("Ben","Young", email="[email protected]", role="aut"),
88
person("Jorge","Vendries", email="[email protected]", role="aut"),

R/CalculationFunctions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,6 @@ calculateGhoshB <- function(model, use_domestic_requirements = FALSE) {
726726
#' @param GhoshB Ghosh matrix B
727727
#' @return G, Ghosh matrix G
728728
calculateGhoshG <- function(GhoshB) {
729-
G <- useeior:::calculateLeontiefInverse(GhoshB)
729+
G <- calculateLeontiefInverse(GhoshB)
730730
return(G)
731731
}

R/DataDocumentation.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@
817817
#' Detail Margins (Before Redef) table for 2017 (2017 schema)
818818
#' @format A dataframe with 58051 obs. and 9 variables:
819819
#' \describe{
820-
#' \item{NIPACode}{text code}
821-
#' \item{MarginsCategory}{text category name, like 'Therapeutic medical equipment'}
820+
#' \item{IndustryCode}{text code}
821+
#' \item{IndustryDescription}{text category name, like 'Therapeutic medical equipment'}
822822
#' \item{CommodityCode}{BEA_2017_Detail_Code}
823823
#' \item{CommodityDescription}{BEA_2017_Detail_Name}
824824
#' \item{ProducersValue}{USD2017}
@@ -833,8 +833,8 @@
833833
#' Detail Margins (Before Redef) table for 2012 (2017 schema)
834834
#' @format A dataframe with 58032 obs. and 9 variables:
835835
#' \describe{
836-
#' \item{NIPACode}{text code}
837-
#' \item{MarginsCategory}{text category name, like 'Therapeutic medical equipment'}
836+
#' \item{IndustryCode}{text code}
837+
#' \item{IndustryDescription}{text category name, like 'Therapeutic medical equipment'}
838838
#' \item{CommodityCode}{BEA_2017_Detail_Code}
839839
#' \item{CommodityDescription}{BEA_2017_Detail_Name}
840840
#' \item{ProducersValue}{USD2017}

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/IOFunctions.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ generateDomesticUse <- function(Use, Import, model) {
199199
# needs to be subtracted from the original Import matrix
200200
if (model$specs$BasePriceType == "BAS") {
201201
# Find "MDTY - import duties" in Supply table
202+
schema <- getSchemaCode(model$specs)
202203
Supply <- get(paste(na.omit(c(model$specs$BaseIOLevel, "Supply", model$specs$IOYear, schema)),
203204
collapse = "_")) * 1E6
204205
ImportDuty <- Supply[rownames(Import), "MDTY"]
@@ -257,10 +258,10 @@ convertUsefromPURtoBAS <- function(UseSUT_PUR, specs, io_codes) {
257258
# Load UsePRO and UsePUR under Make-Use framework
258259
Redef <- ifelse(specs$BasewithRedefinitions, "AfterRedef", "BeforeRedef")
259260
schema <- getSchemaCode(specs)
260-
UsePUR <- get(paste(na.omit(c(specs$BaseIOLevel, "Use", specs$IOYear, "PUR", Redef, specs)), collapse = "_"))
261-
UsePRO <- get(paste(na.omit(c(specs$BaseIOLevel, "Use", specs$IOYear, "PRO", Redef, specs)), collapse = "_"))
261+
UsePUR <- get(paste(na.omit(c(specs$BaseIOLevel, "Use", specs$IOYear, "PUR", Redef, schema)), collapse = "_"))
262+
UsePRO <- get(paste(na.omit(c(specs$BaseIOLevel, "Use", specs$IOYear, "PRO", Redef, schema)), collapse = "_"))
262263
# Load Supply table
263-
Supply <- get(paste(na.omit(c(specs$BaseIOLevel, "Supply", specs$IOYear, specs)), collapse = "_"))
264+
Supply <- get(paste(na.omit(c(specs$BaseIOLevel, "Supply", specs$IOYear, schema)), collapse = "_"))
264265

265266
# Convert from PUR to PRO by removing margins obtained from Supply table
266267
rows <- io_codes$Commodities

R/LoadMargins.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ getMarginsTable <- function (model) {
1717
# Change in inventory has negative margins for positive change, which does not accurately portray actual margins either.
1818
purchaser_removal <- sapply(list("Export", "Import", "ChangeInventories"), getVectorOfCodes,
1919
ioschema = model$specs$BaseIOSchema, iolevel = "Detail")
20-
MarginsTable <- MarginsTable[!MarginsTable$NIPACode%in%purchaser_removal,]
20+
# column names from Margins Tables from 2012 schema were not fixed
21+
col <- ifelse("NIPACode" %in% names(MarginsTable), "NIPACode", "IndustryCode")
22+
MarginsTable <- MarginsTable[!MarginsTable[[col]] %in% purchaser_removal,]
2123
# Remove Scrap, Used and secondhand goods, and Non-comparable imports, and Rest of world adjustment commodities
2224
commodity_removal <- sapply(list("Scrap", "UsedGoods", "NonComparableImport", "RoWAdjustment"), getVectorOfCodes,
2325
ioschema = model$specs$BaseIOSchema, iolevel = model$specs$BaseIOLevel)

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

data-raw/BEAData.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ getBEADetailMarginsBeforeRedef <- function(year, schema_year = NULL) {
10891089
# Trim table, assign column names
10901090
Margins <- Margins[!is.na(Margins[, 4]), ][-1, ]
10911091
rownames(Margins) <- NULL
1092-
colnames(Margins) <- c("NIPACode", "MarginsCategory",
1092+
colnames(Margins) <- c("IndustryCode", "IndustryDescription",
10931093
"CommodityCode", "CommodityDescription",
10941094
"ProducersValue", "Transportation",
10951095
"Wholesale", "Retail", "PurchasersValue")
-39 Bytes
Binary file not shown.
-13 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)