Skip to content

Commit 70fbebf

Browse files
Merge pull request #56 from NEFSC/stephaniedev
Stephaniedev - commercial indicators script and vignette
2 parents 2ab39f5 + 28b8ad2 commit 70fbebf

9 files changed

Lines changed: 284 additions & 198 deletions

R/get_commercial_data.R

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
#' overview-- This code creates six economic commercial fishing indicators used in ESP work.
77
#' The code below pulls data, deflates any monetary values and formats data to what is needed for the time series plots.
88
#' Must have access to the 'NEFSC_GARFO' schema in Oracle to run this code.
9-
#' Indicators created: Commercial Landings (LBS): The total weight of the species landed (e.g., Commercial_LONGFINSQUID_Landings_LBS).
109
#'
10+
#' Indicators created: Commercial Landings (LBS): The total weight of the species landed (e.g., Commercial_LONGFINSQUID_Landings_LBS).
1111
#' Number of Commercial Vessels: The count of unique permits landing that species (e.g., N_Commercial_Vessels_Landing_LONGFINSQUID).
12-
#' Average Price per Pound: The average annual price, winsorized to handle outliers and adjusted for inflation (e.g., AVGPRICE_LONGFINSQUID_2024_DOLlb).
13-
#' Total Annual Revenue: The total value of all landings for that species, adjusted for inflation (e.g., TOTALANNUALREV_LONGFINSQUID_2024Dols).
14-
#' Average Revenue per Vessel: The average revenue earned per permit per year, adjusted for inflation (e.g., AVGVESREVperYr_LONGFINSQUID_2024_DOLlb).
15-
#' Average Annual Diesel Price: The price of Ultra-Low-Sulfur No. 2 Diesel (from FRED), adjusted for inflation (e.g., AVGANNUAL_DIESEL_PRICE2024dols).
12+
#' Average Price per Pound: The average annual price, winsorized to handle outliers and adjusted for inflation (e.g., AVGPRICE_LONGFINSQUID_2025_DOLlb).
13+
#' Total Annual Revenue: The total value of all landings for that species, adjusted for inflation (e.g., TOTALANNUALREV_LONGFINSQUID_2025Dols).
14+
#' Average Revenue per Vessel: The average revenue earned per permit per year, adjusted for inflation (e.g., AVGVESREVperYr_LONGFINSQUID_2025_DOLlb).
15+
#' Average Annual Diesel Price: The price of Ultra-Low-Sulfur No. 2 Diesel (from FRED), adjusted for inflation (e.g., AVGANNUAL_DIESEL_PRICE2025dols).
1616
#'
1717
#' This uses CFDERS data but may need to be updated to CAMs
1818
#'
19-
#' before running!!!
19+
#' before running!!!
2020
#' make sure you are connected to VPN
2121
#' ensure all packages are installed
2222
#' you have a folder in your directory called "data"
@@ -27,7 +27,7 @@
2727
#' @param ora_id username for Oracle connection (in quotation marks)
2828
#' @param oraprod_pw password for Oracle connection (in quotation marks)
2929
#' @param spp_name the name of the species you want to pull (e.g., "LONGFINSQUID")
30-
#' @param nespp3_codes the NESPP3 codes for the species you want to (e.g., "('801')") - note the single quotes inside the string for SQL
30+
#' @param nespp3_codes the NESPP3 codes for the species you want to pull (e.g., "('801')") - note the single quotes inside the string for SQL
3131
#' @param START.YEAR the first year you want to pull (e.g., 1996)
3232
#' @param END.YEAR the last year you want to pull (e.g., 2025)
3333
#' @param deflate_yr the year you want to deflate to (e.g, 2025)
@@ -108,12 +108,11 @@ get_commercial_data <- function(
108108
mutate(
109109
CATEGORY = "Commercial",
110110
INDICATOR_NAME = paste0("Commercial_", spp_name, "_Landings_LBS"),
111-
SIGN = "N/A",
112111
INDICATOR_TYPE = "Socioeconomic"
113112
) %>%
114113
# Rename the sum column to DATA_VALUE (Equivalent to Stata rename)
115114
rename(DATA_VALUE = !!paste0("TOTAL_", spp_name)) %>%
116-
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, SIGN, INDICATOR_TYPE)
115+
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, INDICATOR_TYPE)
117116

118117
#
119118

@@ -139,13 +138,12 @@ get_commercial_data <- function(
139138
CATEGORY = "Commercial",
140139
# This creates the long name you want in the final table
141140
INDICATOR_NAME = paste0("N_Commercial_Vessels_Landing_", spp_name),
142-
SIGN = "N/A",
143141
INDICATOR_TYPE = "Socioeconomic"
144142
) %>%
145143
# Now this rename will work because the SQL alias matches 'N_VESSELS'
146144
# Note: Oracle often returns names in UPPERCASE, so we check for both.
147145
rename(DATA_VALUE = any_of(c("N_VESSELS", "N_vessels"))) %>%
148-
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, SIGN, INDICATOR_TYPE)
146+
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, INDICATOR_TYPE)
149147

150148
# 4. View the result
151149
print(head(Nvessels_final))
@@ -193,10 +191,9 @@ get_commercial_data <- function(
193191
DATA_VALUE = (AVG_NOMINAL_PRICE / GDPDEF) * base_index_val,
194192
CATEGORY = "Commercial",
195193
INDICATOR_NAME = paste0("AVGPRICE_", spp_name, "_", deflate_yr, "_DOLlb"),
196-
SIGN = "N/A",
197194
INDICATOR_TYPE = "Socioeconomic"
198195
) %>%
199-
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, SIGN, INDICATOR_TYPE)
196+
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, INDICATOR_TYPE)
200197

201198
# --- 4. Cleanup ---
202199

@@ -228,10 +225,9 @@ get_commercial_data <- function(
228225
DATA_VALUE = (TOTAL_REV / GDPDEF) * base_index_val,
229226
CATEGORY = "Commercial",
230227
INDICATOR_NAME = paste0("TOTALANNUALREV_", spp_name, "_", deflate_yr, "Dols"),
231-
SIGN = "N/A",
232228
INDICATOR_TYPE = "Socioeconomic"
233229
) %>%
234-
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, SIGN, INDICATOR_TYPE)
230+
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, INDICATOR_TYPE)
235231

236232
################## Fuel Prices ##################
237233

@@ -254,10 +250,9 @@ get_commercial_data <- function(
254250
DATA_VALUE = (DDFUELNYH / GDPDEF) * base_index_val,
255251
CATEGORY = "Commercial",
256252
INDICATOR_NAME = paste0("AVGANNUAL_DIESEL_PRICE", deflate_yr, "dols"),
257-
SIGN = "N/A",
258253
INDICATOR_TYPE = "Socioeconomic"
259254
) %>%
260-
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, SIGN, INDICATOR_TYPE)
255+
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, INDICATOR_TYPE)
261256

262257
############ Average Revenue Per Vessel ##################
263258

@@ -280,10 +275,9 @@ get_commercial_data <- function(
280275
DATA_VALUE = (AVG_VESSEL_REV / GDPDEF) * base_index_val,
281276
CATEGORY = "Commercial",
282277
INDICATOR_NAME = paste0("AVGVESREVperYr_", spp_name, "_", deflate_yr, "_DOLlb"),
283-
SIGN = "N/A",
284278
INDICATOR_TYPE = "Socioeconomic"
285279
) %>%
286-
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, SIGN, INDICATOR_TYPE)
280+
select(YEAR, DATA_VALUE, CATEGORY, INDICATOR_NAME, INDICATOR_TYPE)
287281

288282
##disconnect from oracle
289283
dbDisconnect(conn)
@@ -322,12 +316,3 @@ get_commercial_data <- function(
322316

323317
}
324318

325-
get_commercial_data(
326-
ora_id = "user",
327-
oraprod_pw = "password",
328-
spp_name = "LONGFINSQUID",
329-
nespp3_codes = "('801')",
330-
START.YEAR = 1996,
331-
END.YEAR = 2025,
332-
deflate_yr = 2025
333-
)

0 commit comments

Comments
 (0)