Skip to contents

Creates a matrix with one row per claim and one column per calendar year

Usage

generate_history_per_claim(data, column, first_orig_year, last_orig_year)

Arguments

data

dataframe with at least the columns 'Claim_id', 'Calendar_year' and col_name

column

column to sum across

first_orig_year

desired first origin year, will be treated as the first observed calendar year

last_orig_year

desired last origin year, will be treated as the last observed calendar year

Value

matrix containing claims history per claim

Examples

claims_data <- data.frame(Claim_id = c(rep("Claim1", 3), "Claim2", rep("Claim3", 2)),
                          Origin_year = c(rep(2010, 4), rep(2012, 2)),
                          Calendar_year = c(2010:2012, 2012, 2012, 2014),
                          Dev_year_since_large = c(0, 1, 2, 1, 1, 2),
                          Cl_payment_cal = rep(1000, 6))
print(claims_data)
#>   Claim_id Origin_year Calendar_year Dev_year_since_large Cl_payment_cal
#> 1   Claim1        2010          2010                    0           1000
#> 2   Claim1        2010          2011                    1           1000
#> 3   Claim1        2010          2012                    2           1000
#> 4   Claim2        2010          2012                    1           1000
#> 5   Claim3        2012          2012                    1           1000
#> 6   Claim3        2012          2014                    2           1000
generate_history_per_claim(claims_data, "Cl_payment_cal", 2009, 2014)
#>         Calendar_year
#> Claim_id 2009 2010 2011 2012 2013 2014
#>   Claim1    0 1000 1000 1000    0    0
#>   Claim2    0    0    0 1000    0    0
#>   Claim3    0    0    0 1000    0 1000