README.md 3.65 KB
Newer Older
Carl Corder's avatar
Carl Corder committed
1
# ACTS 475/875: Actuarial Applications in Practice
Carl Corder's avatar
Carl Corder committed
2

Carl Corder's avatar
Carl Corder committed
3
Lincoln Financial Group:  Relationship to Needed by Renewal.
Carl Corder's avatar
Carl Corder committed
4

Carl Corder's avatar
Carl Corder committed
5
6
7
8
9
10
# Data Transformation
```r
install.packages("readxl")
install.packages("dplyr")
library("dplyr")
library("readxl")
Carl Corder's avatar
Carl Corder committed
11

Carl Corder's avatar
Carl Corder committed
12
13
14
15
16
17
# read in data
fileName <- "~/Desktop/RtnData.xlsx"
data <- read_excel(fileName, sheet = "Data")
sic <- read_excel(fileName, sheet = "SIC")
# left outer-join on industry code
rtnData <- merge(x = data, y = sic, by.x = "INDUSTRY_CODE", by.y = "SIC_CODE", all.x = TRUE)
Carl Corder's avatar
Carl Corder committed
18

Carl Corder's avatar
Carl Corder committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# drop VAL_DATE column
rtnData <- rtnData %>% select(-c("VAL_DATE"))

# remove NBOC and Amendment rows
rtnData <- rtnData %>% filter(EVENT_TYPE != "NBOC")
rtnData <- rtnData %>% filter(EVENT_TYPE != "Amendment")

# use only positive premiums
rtnData <- rtnData %>% filter(NEEDED_PREMIUM > 0 & FINAL_QUOTED_PREMIUM > 0)

# standardize renewals and convert to numeric
rtnData <- rtnData %>% mutate(RENEWAL_INSTANCE = case_when(EVENT_TYPE == "New Business" ~ "0",
                                                           RENEWAL_INSTANCE == "1st Renewal" ~ "1",
                                                           RENEWAL_INSTANCE == "2nd Renewal" ~ "2",
                                                           RENEWAL_INSTANCE == "2nd+" ~ "3",
                                                           RENEWAL_INSTANCE == "3rd Renewal +" ~ "3",
                                                           TRUE ~ as.character(RENEWAL_INSTANCE)))

rtnData$RENEWAL_INSTANCE <- as.numeric(rtnData$RENEWAL_INSTANCE)

# format date timestamps
rtnData$RAE_EFF_DATE <- as.Date(rtnData$RAE_EFF_DATE, "%y-%m-%d")
rtnData$COV_EFF_DATE <- as.Date(rtnData$COV_EFF_DATE, "%y-%m-%d")

# set date range >= 2017
rtnData <- rtnData %>% filter(RAE_EFF_DATE >= as.Date("2017-01-01"))
rtnData <- rtnData %>% filter(COV_EFF_DATE >= as.Date("2017-01-01"))

# clean up sales office names
rtnData <- rtnData %>% mutate(SALES_OFFICE = tolower(SALES_OFFICE))
rtnData <- rtnData %>% mutate(SALES_OFFICE = case_when(SALES_OFFICE == "central philadelphia" ~ "philadelphia",
                                                       SALES_OFFICE == "chicago/indy/milwaukee" ~ "chicago",
                                                       SALES_OFFICE == "home" ~ "ft wayne",
                                                       SALES_OFFICE == "miami/orlando/tampa" ~ "miami",
                                                       SALES_OFFICE == "washington dc" ~ "washington d.c.",
                                                       TRUE ~ as.character(SALES_OFFICE)))

# map sales office to sales region
rtnData <- rtnData %>% mutate(UW_REGION = tolower(UW_REGION))
regions <- list("home" = c("ft wayne"),
                "central" = c("chicago","cincinnati","cleveland","detroit","ft lauderdale","indianapolis","miami","milwaukee","minneapolis","omaha","orlando","pittsburgh","st. louis","tampa"),
                "east" = c("atlanta","boston","charlotte","long island","nashville","new jersey","new york","parsnippany","philadelphia","portland, me","rochester","washington d.c.","white plains"),
                "west" = c("dallas","denver","houston","kansas city","los angeles","orange county","phoenix","portland, or","sacramento","san diego","san francisco","seattle"))

rtnData <- rtnData %>% mutate(UW_REGION = case_when(SALES_OFFICE %in% regions$home ~ "home",
                                                    SALES_OFFICE %in% regions$central ~ "central",
                                                    SALES_OFFICE %in% regions$east ~ "east",
                                                    SALES_OFFICE %in% regions$west ~ "west",
                                                    TRUE ~ as.character(UW_REGION)))
Carl Corder's avatar
Carl Corder committed
68
```
Carl Corder's avatar
Carl Corder committed
69
70