Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get employment table (fixes #43) #44

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ Remotes:
License: file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.0
RoxygenNote: 7.3.1
Suggests:
testthat (>= 2.1.0)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(buildFullTwoRegionIOTable)
export(buildStateSupplyModel)
export(buildStateUseModel)
export(buildTwoRegionUseModel)
export(getStateEmploymentTable)
export(getVectorOfCodes)
export(loadStateIODataFile)
export(plotICFandRPC)
Expand Down
28 changes: 17 additions & 11 deletions R/StateSupplyFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,29 @@ estimateStateCommodityOutputRatiofromAlternativeSources <- function(year) {
return(StateCommodityOutputRatio)
}

#' Load BEA State Employment data from pre-saved .rds files and State Employment
#' FlowBySector data from flowsa.
#' Map to BEA Summary sectors.
#' @param year A numeric value between 2007 and 2017 specifying the year of interest.
#' @return A data frame contains State Employment by BEA Summary.
getStateEmploymentbyBEASummary <- function(year) {
# BEA State Emp
BEAStateEmp <- loadStateIODataFile(paste0("State_Employment_", year),
ver = model_ver)
#' Get a table of state employment by BEA Summary sector.
#' @param year A numeric value specifying the year of interest.
#' @return A data frame containing employment count by state and BEA Summary sector.
#' @export
getStateEmploymentTable <- function(year) {
BEAStateEmp <- loadStateIODataFile(paste0("State_Employment_", year))
EmptoBEAmapping <- loadBEAStateDatatoBEASummaryMapping("Employment")
BEAStateEmp <- merge(BEAStateEmp[, c("GeoName", "LineCode", as.character(year))],
EmptoBEAmapping, by = "LineCode")
# Aggregate StateEmployment by BEA
EmptoBEAmapping, by = "LineCode")
BEAStateEmp <- stats::aggregate(BEAStateEmp[, as.character(year)],
by = list(BEAStateEmp$BEA_2012_Summary_Code,
BEAStateEmp$GeoName), sum)
colnames(BEAStateEmp) <- c("BEA_2012_Summary_Code", "State", "Emp")
return(BEAStateEmp)
}

#' Load BEA State Employment data from pre-saved .rds files and State Employment
#' FlowBySector data from flowsa.
#' Map to BEA Summary sectors.
#' @param year A numeric value between 2007 and 2017 specifying the year of interest.
#' @return A data frame contains State Employment by BEA Summary.
getStateEmploymentbyBEASummary <- function(year) {
BEAStateEmp <- getStateEmploymentTable(year)
# Employment FlowBySector from flowsa
EmpFBS <- getFlowsaData("Employment", year)
EmpFBS <- mapFlowBySectorfromNAICStoBEA(EmpFBS, year, "Summary")
Expand Down
7 changes: 6 additions & 1 deletion R/UtilityFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ findLatestStateIODatainLocalDirectory <- function(filename) {
}

#' Load StateIO data file from Data Commons or local data directory.
#'
#' If the file is not found locally, it will be downloaded from Data Commons. Available
#' files can be found on https://dmap-data-commons-ord.s3.amazonaws.com/index.html#stateio/.
#' These include Use, DomesticUse, and IndustryOutput tables, among others.
#'
#' @param filename A string specifying filename, e.g. "State_Summary_Use_2017".
#' @param ver A string specifying version of the data, default is NULL, can be "v0.1.0".
#' @return A StateIO data product (usually a list of dataframes).
Expand All @@ -300,7 +305,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://dmap-data-commons-ord.s3.amazonaws.com/index.html?prefix=stateio/. ",
"https://dmap-data-commons-ord.s3.amazonaws.com/index.html#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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ writeStateIODatatoCSV <- ("State_Summary_DomesticUse_2012", "Georgia", outputfol
writeStateIODatatoCSV <- ("TwoRegion_Summary_DomesticUse_2012", "Georgia", outputfolder)
```

Employment data is also available for each state and year, containing employment by BEA Summary sector.

```r
Employment_2012 <- getStateEmploymentTable(2012)
# BEA_2012_Summary_Code State Emp
# 1 111CA Alabama 38191
# 2 113FF Alabama 15773
# 3 211 Alabama 4334
# 4 212 Alabama 8205
```

Industry output data is also available, and can be used to calculate the direct requirements matrix.

```r
OneRegionIndustryOutput_2012 <- loadStateIODataFile("State_Summary_IndustryOutput_2012")
GA_IndustryOutput_2012 <- OneRegionIndustryOutput_2012[["Georgia"]]
# Drop extra rows from the DomesticUse table; these do not correspond to actual BEA Summary industries.
GA_DomesticUse_2012 <- GA_DomesticUse_2012[!rownames(GA_DomesticUse_2012) %in% c("V001", "V002", "V003", "Used", "Other"), ]
# Calculate the direct requirements matrix
GA_DirectRequirements_2012 <- GA_DomesticUse_2012 / GA_IndustryOutput_2012$Output
```

### Use for Developers (usage type #2)

For studying, replicating or modify the code, users will want to clone or copy the source code and review the code in R. See more in [Instructions for Developers](https://github.com/USEPA/stateior/wiki/Instructions-for-developers).
Expand Down
17 changes: 17 additions & 0 deletions man/getStateEmploymentTable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/loadStateIODataFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading