Commit d4ce0db3 authored by Carl Corder's avatar Carl Corder
Browse files

map situs state to region (east,central,west)

parent 9141d0df
......@@ -19,7 +19,7 @@ tax <- read_excel(input, sheet = "Tax") # join by state
data <- data %>% select(-c(ICOS, WAIVER_IBNR, GAAP_RESV, WAIVER_RESERVE))
# create date from incurred year and month
data <- data %>% mutate(INC_DATE = as.Date(paste(INC_YEAR, INC_MONTH, 01, sep = "-")))
data <- data %>% mutate(INC_DATE = as.Date(paste(INC_YEAR, INC_MONTH, "01", sep = "-")))
# drop redundant incurred date columns
data <- data %>% select(-c(INC_MONTH, INC_YEAR, INC_MONTHYEAR))
......@@ -56,17 +56,20 @@ data <- merge(x = data, y = tax, by.x = "STATE", by.y = "STATE", all.x = TRUE)
# remove rows with unmapped state tax (e.g. 91, FO)
data <- data %>% filter(!is.na(PREMIUM_TAX))
# get internal expense from annual net premium
# situs state to region map
regions <- list("east" = c("AL","CT","DC","DE","GA","MA","MD","ME","MS","NC","NH","NJ","NY","PA","RI","SC","TN","VA","VT"),
"central" = c("FL","IA","IL","IN","KY","MI","MN","MO","ND","NE","OH","SD","WI","WV"),
"west" = c("AK","AR","AZ","CA","CO","HI","ID","KS","LA","MT","NM","NV","OK","OR","TX","UT","WA","WY"))
# create region column
data <- data %>% mutate(REGION = case_when(STATE %in% regions$east ~ "east",
STATE %in% regions$central ~ "central",
STATE %in% regions$west ~ "west"))
# get internal expense from estimated annual net premium
get_internal_expense <- function(premium) {
sapply(premium, function(x) {
n <- nrow(expense)
if (x < expense$EST_ANN_NET_PREM_MIN[1]) {
return(expense$INTERNAL_EXPENSE[1])
}
if (x > expense$EST_ANN_NET_PREM_MAX[n]) {
return(expense$INTERNAL_EXPENSE[n])
}
for (i in 1:n) {
for (i in 1:nrow(expense)) {
if (x >= expense$EST_ANN_NET_PREM_MIN[i] &
x < expense$EST_ANN_NET_PREM_MAX[i]) {
return(expense$INTERNAL_EXPENSE[i])
......@@ -128,7 +131,7 @@ data <- data %>% mutate(POLICY_EFFECTIVE_DATE = as.Date(data$POLICY_EFFECTIVE_DA
# re-order columns
data <- data %>% select("GROUP_ID", "DIST_ID", "REP_ID",
"REG_OFFICE", "STATE", "INDUSTRY", "SUB_INDUSTRY",
"REG_OFFICE", "STATE", "REGION", "INDUSTRY", "SUB_INDUSTRY",
"AVG_SALARY", "AVG_AGE", "PCT_FEMALE",
"POLICY_EFFECTIVE_DATE", "INC_DATE", "POLICY_DURATION",
"COVG_CODE", "TRUE_GROUP_VOL", "ACTIVE_TERMED", "LTD_INDICATOR",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment