The license history table accounts for multi-year/lifetime licenses by including
1 row for every year a license is held. The input data frame should only have 1 record
per customer-year (ensured by running rank_sale
beforehand).
make_history(sale_ranked, yrs, carry_vars = NULL, yrs_lapse = yrs, show_diagnostics = FALSE)
sale_ranked | data frame: Sales table from which license history will be made; must include at least 3 variables (cust_id, year, duration) |
---|---|
yrs | numeric: Years in sales data (column 'year') from which to create license history |
carry_vars | character: additional variables to carry over from previous year (for multi-year and lifetime licenses). |
yrs_lapse | numeric: years to include in lapse calculation (defaults to yrs). If NULL, lapse will not be calculated (useful for mid-year results) |
show_diagnostics | logical: If TRUE, will include intermediate variables in the
output dataset, necessary for running checks: |
The output data frame includes the following variables:
cust_id: Customer ID
year: License Year
carry_vars: One or more optional variables to include; ensures multi-year/lifetime records are complete in future years.
duration_run: A duration variable that accounts for multi-year/lifetimes.
lapse: Lapse next year? (1=Yes, 0=No). Only included if yrs_lapse != NULL
R3: R3 group this year (1=carried, 2=renewed, 3=reactivated, 4=recruited). Only included if more than 5 years are present.
Salic Function Reference: salic
Other license history functions: history_check
,
rank_sale
#>history <- make_history(sale_ranked, 2008:2018, "res") # history includes more rows than sale_ranked if multi-year/lifetimes are present left_join(count(history, year), count(sale_ranked, year), by = "year")#> # A tibble: 11 x 3 #> year n.x n.y #> <int> <int> <int> #> 1 2008 6393 6393 #> 2 2009 7591 7428 #> 3 2010 7775 7475 #> 4 2011 7819 7306 #> 5 2012 8243 7447 #> 6 2013 8273 7245 #> 7 2014 8970 7757 #> 8 2015 9086 7660 #> 9 2016 9161 7568 #> 10 2017 9389 7673 #> 11 2018 9206 7281