Skip to content

Commit

Permalink
Merge branch 'dev' into disagg
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-young committed Oct 26, 2024
2 parents 45383f4 + 37e1c1c commit cfad0cd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
"creators": [
{
"affiliation": "General Dynamics Information Technology, Inc.",
"name": "Mo Li"
"name": "Mo Li",
"orcid": "https://orcid.org/0000-0002-3672-1622"
},
{
"affiliation": "US Environmental Protection Agency",
"name": "Wesley Ingwersen"
"name": "Wesley Ingwersen",
"orcid": "https://orcid.org/0000-0002-9614-701X"
},
{
"affiliation": "University of Florida",
"name": "Joao-Pedro Ferreira"
"name": "Joao-Pedro Ferreira",
"orcid": "https://orcid.org/0000-0002-6726-7856"
},
{
"affiliation": "University of Florida",
"name": "Christa Court"
"name": "Christa Court",
"orcid": "https://orcid.org/0000-0002-2690-9015"
},
{
Expand Down
1 change: 1 addition & 0 deletions R/BuildModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ assembleTwoRegionIO <- function(year, iolevel, disagg_specs=NULL) {

## Two-region Domestic Use table with interregional exports and imports
TwoRegionIO[["DomesticUsewithTrade"]][[state]] <- TwoRegionDomesticUseModel[1:4]
TwoRegionIO[["UsewithTrade"]][[state]] <- TwoRegionUseModel[1:4]

## Two-region Commodity Output
SoI_CommodityOutput <- rowSums(TwoRegionDomesticUseModel[["SoI2SoI"]][, c(industries, FD_cols, ITA_col, "ExportResidual")]) +
Expand Down
12 changes: 8 additions & 4 deletions R/UtilityFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ getFlowsaData <- function(dataname, year) {
# Define file directory
directory <- file.path(rappdirs::user_data_dir(), subdirectory)
if (!file.exists(file.path(directory, filename))) {
url <- paste0("https://edap-ord-data-commons.s3.amazonaws.com/", subdirectory)
url <- paste0("https://dmap-data-commons-ord.s3.amazonaws.com/", subdirectory)
logging::loginfo(paste0("file not found, downloading from ", url))
# Check for and create directory if necessary
if (!file.exists(directory)) {
Expand All @@ -201,7 +201,7 @@ getFlowsaData <- function(dataname, year) {
#' "flowsa/FlowByActivity".
#' @return A dataframe of StateIO data registry on Data Commons.
getRegistryonDataCommons <- function(data_group = "stateio") {
registry_ls <- aws.s3::get_bucket(bucket = "edap-ord-data-commons",
registry_ls <- aws.s3::get_bucket(bucket = "dmap-data-commons-ord",
prefix = data_group)
registry <- cbind.data.frame(basename(sapply(registry_ls, `[[`, "Key")),
sapply(registry_ls, `[[`, "LastModified"),
Expand All @@ -217,6 +217,10 @@ findLatestStateIODataonDataCommons <- function(filename) {
registry <- getRegistryonDataCommons(data_group = "stateio")
f <- registry[startsWith(registry$Key, filename) &
endsWith(registry$Key, ".rds"), ]
f$version <- sub(paste0(filename, "_"), "", f$Key)
f$version <- sub(".[^.]*$", "", f$version)
# sort so latest version on top in case of duplicate LastModified dates
f <- f[order(f$version, decreasing=TRUE), ]
f <- basename(f[which.max(as.Date(f$LastModified)), "Key"])
if (length(f) == 0) {
stop(paste(filename, "not avaialble on Data Commons."))
Expand Down Expand Up @@ -255,7 +259,7 @@ downloadStateIODatafromDataCommons <- function(filename, ver = NULL) {
f <- paste0(paste(filename, ver, sep = "_"), ".rds")
}
# Download file
url <- "https://edap-ord-data-commons.s3.amazonaws.com/stateio"
url <- "https://dmap-data-commons-ord.s3.amazonaws.com/stateio"
utils::download.file(file.path(url, f),
file.path(directory, f), mode = "wb", quiet = TRUE)
}
Expand Down Expand Up @@ -300,7 +304,7 @@ loadStateIODataFile <- function(filename, ver = NULL) {
"not found in local data directory, either."))
message("Please confirm ", filename, " is correctly spelled. ",
"You should be able to find the correctly spelled file on ",
"https://edap-ord-data-commons.s3.amazonaws.com/index.html?prefix=stateio/. ",
"https://dmap-data-commons-ord.s3.amazonaws.com/index.html?prefix=stateio/. ",
"If it's not found there, please open an issue at ",
"https://github.com/USEPA/stateior/issues/new ",
"and inform package maintainers.\n",
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# stateior <img src="inst/img/logo.png" align="right" width="240" />
<!-- badges: start -->
[![R CI/CD test](https://github.com/USEPA/stateior/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/USEPA/stateior/actions/workflows/R-CMD-check.yaml)
[![v0.1.0](http://img.shields.io/badge/v0.1.0-10.5281/zenodo.6954423-blue.svg)](https://doi.org/10.5281/zenodo.6954423)
[![DOI](https://zenodo.org/badge/279373285.svg)](https://zenodo.org/badge/latestdoi/279373285)
[![StateIO paper](http://img.shields.io/badge/StateIO%20paper-10.3390/app12094469-blue.svg)](https://doi.org/10.1177/01600176221145874)
<!-- badges: end -->

`stateior` is an R package for building multi-regional economic input-output (MRIO) tables of states in the United States, refered to as **StateIO** models.
Currently, `stateior` is capable of creating IO tables for each US state and building two-region MRIO models based on those state IO tables at the [BEA](https://www.bea.gov/) Summary level of resolution in the US for all years from 2012-2020.
The two regions are State of Interest (SoI) and Rest of the US (RoUS).
`stateior` was initially conceived in support of creating state-specific versions of [USEEIO models](https://www.epa.gov/land-research/us-environmentally-extended-input-output-useeio-models), but may be used for other purposes where state input-output tables are used.
The methodology used to build the StateIO models is described in a [paper in International Regional Science Review](https://doi.org/10.1177/01600176221145874).
The package is intended to add transparency and reproducibility to the complex process of generating subnational input-output tables, which are not compiled by any statistical agency.

`stateior` implements a robust commodity-industry modeling framework that models supply, use and trade of commodities by industries and final users in 50 U.S. states plus the District of Columbia and includes international import and export.
Expand All @@ -27,10 +30,15 @@ Install the most recent release version of `stateior` and attach it to the curre

```r
install.packages("devtools")
devtools::install_github("USEPA/stateior@v0.2.0")
devtools::install_github("USEPA/stateior")
library(stateior)
```

```r
# For a specific release:
devtools::install_github("USEPA/[email protected]")
```

Load desired StateIO data. See [One Region Data](format_specs/OneRegionData.md#data) and [Two Region Data](format_specs/TwoRegionData.md#data) for names and details of one- and two-region MRIO data sets that are currently available, respectively.

```r
Expand Down
2 changes: 1 addition & 1 deletion format_specs/OneRegionData.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ One region IO data created by `stateior` are data for single states saved as `.r
| Commodity Output | State_Summary_CommodityOutput_`year`_`version` | numeric vector | [Output Vectors](https://github.com/USEPA/useeior/blob/v1.1.0/format_specs/Model.md#output-vectors) |
| Industry Output | State_Summary_IndustryOutput_`year`_`version` | numeric vector | [Output Vectors](https://github.com/USEPA/useeior/blob/v1.1.0/format_specs/Model.md#output-vectors)|

<sup>1</sup> Data names on [Data Commons](https://edap-ord-data-commons.s3.amazonaws.com/index.html?prefix=stateio/). `year` and `version` are subject to change.
<sup>1</sup> Data names on [Data Commons](https://dmap-data-commons-ord.s3.amazonaws.com/index.html?prefix=stateio/). `year` and `version` are subject to change.

<sup>2</sup> These Use tables add, as the final column, the international trade adjustment (ITA) containing the value of all transportation and insurance services and customs duties

2 changes: 1 addition & 1 deletion format_specs/TwoRegionData.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Each two-region matrix has a four-quadrant structure. In each matrix, `SoI` is r
| Commodity Output | TwoRegion_Summary_CommodityOutput_`year`_`version` | numeric vector | [Two-region total output by commodity](#Two-Region-Output-Vectors) |
| Industry Output | TwoRegion_Summary_IndustryOutput_`year`_`version` | numeric vector | [Two-region total output by industry](#Two-Region-Output-Vectors) |

<sup>1</sup> Data names on [Data Commons](https://edap-ord-data-commons.s3.amazonaws.com/index.html?prefix=stateio/). `year` and `version` are subject to change.
<sup>1</sup> Data names on [Data Commons](https://dmap-data-commons-ord.s3.amazonaws.com/index.html?prefix=stateio/). `year` and `version` are subject to change.

### Two Region Make
The two-region Make is an `industry x commodity` matrix with amounts of commodities (in model year USD) being made by industries.
Expand Down

0 comments on commit cfad0cd

Please sign in to comment.