Each row is a hooked loan pair, defined as cases where (loan_start <= loan_start_paired) & (loan_start_paired <= loan_end) & (loan_end <= loan_end_paired)
is satisfied.
Note this potentially allows for the hooked loan to have just 1 month. The paired bottom hook loan must be connected to the paired top hook loan.
Format
loan pair dataframe with various top loan and bottom loan attributes
- hhid_Num
household id
- hh_loan_id_nd
non-duplicate loan id, sequential for all loans, top loan
- hh_loan_id_nd_paired
non-duplicate loan id, sequential for all loans, bottom hooked loan
- loan_start
loan start month, top loan
- loan_start_paired
loan start month, bottom hooked loan
- loan_end
loan end month, top loan
- loan_end_paired
loan end month, bottom hooked loan
- forinfm4
name of categorical variable defining loan group types, top loan
- forinfm4_paired
name of categorical variable defining loan group types, bottom hooked loan
- hook_gap_gl
GL: top left - bottom left, GL> 0, the bottom loan is taken out after the top loan.
- hook_gap_gm
GM: bottom left - top right, GM >= 0, the top loan is not due yet or just due when the bottom loan is taken out.
- hook_gap_gr
GR: top right - bottom right, GR > 0, the bottom loan is due after the top loan is due.
Examples
library(dplyr)
library(tidyr)
data(tstm_loans_hooks)
summary(tstm_loans_hooks)
#> hhid_Num hh_loan_id_nd hh_loan_id_nd_paired loan_start
#> Min. : 70203 Min. : 3 Min. : 4 Min. : 0.00
#> 1st Qu.:271309 1st Qu.: 5813 1st Qu.: 5818 1st Qu.: 47.00
#> Median :490327 Median :10407 Median :10409 Median : 77.00
#> Mean :386823 Mean :10169 Mean :10174 Mean : 76.81
#> 3rd Qu.:490638 3rd Qu.:14387 3rd Qu.:14390 3rd Qu.:108.00
#> Max. :531026 Max. :19586 Max. :19587 Max. :160.00
#> loan_start_paired loan_end loan_end_paired forinfm4
#> Min. : 0.00 Min. : 0.00 Min. : 0.0 Length:47754
#> 1st Qu.: 61.00 1st Qu.: 65.00 1st Qu.: 75.0 Class :character
#> Median : 87.00 Median : 91.00 Median :102.0 Mode :character
#> Mean : 88.05 Mean : 93.14 Mean :103.8
#> 3rd Qu.:120.00 3rd Qu.:125.00 3rd Qu.:137.0
#> Max. :160.00 Max. :160.00 Max. :160.0
#> forinfm4_paired hook_gap_gl hook_gap_gm hook_gap_gr
#> Length:47754 Min. : 0.00 Min. : 0.00 Min. : 0.00
#> Class :character 1st Qu.: 3.00 1st Qu.: 0.00 1st Qu.: 2.00
#> Mode :character Median : 8.00 Median : 3.00 Median : 7.00
#> Mean : 11.24 Mean : 5.09 Mean : 10.63
#> 3rd Qu.: 12.00 3rd Qu.: 7.00 3rd Qu.: 12.00
#> Max. :159.00 Max. :159.00 Max. :159.00
print(tstm_loans_hooks)
#> # A tibble: 47,754 × 12
#> hhid_Num hh_loan_id_nd hh_loan_id_nd_paired loan_start loan_start_paired
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 70203 3 4 39 51
#> 2 70203 4 5 51 64
#> 3 70203 4 6 51 64
#> 4 70203 4 7 51 65
#> 5 70203 5 6 64 64
#> 6 70203 5 7 64 65
#> 7 70203 6 7 64 65
#> 8 70203 7 8 65 74
#> 9 70203 7 9 65 74
#> 10 70203 8 9 74 74
#> # ℹ 47,744 more rows
#> # ℹ 7 more variables: loan_end <dbl>, loan_end_paired <dbl>, forinfm4 <chr>,
#> # forinfm4_paired <chr>, hook_gap_gl <dbl>, hook_gap_gm <dbl>,
#> # hook_gap_gr <dbl>
tb_tally <- tstm_loans_hooks %>% group_by(hook_gap_gl, hook_gap_gm, hook_gap_gr) %>% tally() %>% arrange(desc(n))
knitr::kable(tb_tally[1:100,])
#>
#>
#> | hook_gap_gl| hook_gap_gm| hook_gap_gr| n|
#> |-----------:|-----------:|-----------:|----:|
#> | 12| 0| 12| 2233|
#> | 11| 0| 12| 718|
#> | 12| 0| 0| 635|
#> | 0| 0| 12| 626|
#> | 12| 0| 11| 601|
#> | 3| 9| 3| 414|
#> | 12| 0| 13| 367|
#> | 6| 6| 6| 363|
#> | 9| 3| 9| 363|
#> | 13| 0| 12| 339|
#> | 1| 11| 1| 303|
#> | 5| 7| 5| 278|
#> | 11| 0| 13| 272|
#> | 7| 5| 7| 259|
#> | 4| 8| 4| 256|
#> | 11| 0| 0| 256|
#> | 8| 4| 8| 249|
#> | 13| 0| 11| 244|
#> | 11| 1| 11| 230|
#> | 2| 10| 2| 221|
#> | 1| 0| 1| 219|
#> | 10| 2| 10| 205|
#> | 3| 0| 3| 204|
#> | 0| 0| 13| 194|
#> | 0| 12| 0| 194|
#> | 9| 3| 8| 192|
#> | 13| 0| 0| 189|
#> | 0| 0| 11| 188|
#> | 4| 7| 5| 177|
#> | 3| 8| 4| 173|
#> | 10| 1| 11| 164|
#> | 11| 0| 11| 152|
#> | 3| 9| 2| 148|
#> | 7| 5| 6| 147|
#> | 8| 4| 7| 146|
#> | 9| 2| 10| 145|
#> | 10| 2| 9| 141|
#> | 5| 6| 6| 139|
#> | 3| 0| 0| 138|
#> | 6| 6| 5| 138|
#> | 4| 8| 3| 137|
#> | 6| 5| 7| 137|
#> | 2| 10| 1| 135|
#> | 11| 1| 10| 135|
#> | 10| 0| 12| 128|
#> | 0| 11| 1| 127|
#> | 1| 11| 0| 127|
#> | 8| 3| 9| 126|
#> | 1| 10| 2| 125|
#> | 12| 0| 2| 118|
#> | 2| 9| 3| 116|
#> | 0| 0| 3| 111|
#> | 12| 0| 10| 111|
#> | 5| 7| 4| 109|
#> | 7| 4| 8| 107|
#> | 2| 9| 2| 106|
#> | 4| 7| 4| 106|
#> | 8| 3| 8| 106|
#> | 1| 1| 0| 97|
#> | 12| 0| 3| 94|
#> | 9| 2| 9| 93|
#> | 1| 2| 0| 91|
#> | 3| 8| 3| 89|
#> | 8| 5| 7| 87|
#> | 1| 10| 1| 84|
#> | 9| 0| 12| 83|
#> | 3| 2| 0| 77|
#> | 10| 3| 9| 77|
#> | 12| 0| 9| 77|
#> | 12| 0| 1| 76|
#> | 5| 0| 12| 75|
#> | 1| 2| 10| 73|
#> | 1| 12| 0| 73|
#> | 1| 3| 0| 72|
#> | 6| 5| 6| 72|
#> | 2| 10| 3| 71|
#> | 4| 0| 12| 71|
#> | 11| 0| 1| 71|
#> | 1| 0| 0| 69|
#> | 10| 2| 8| 69|
#> | 0| 0| 0| 68|
#> | 2| 1| 0| 68|
#> | 2| 8| 4| 68|
#> | 2| 0| 0| 67|
#> | 5| 6| 5| 67|
#> | 6| 0| 12| 67|
#> | 2| 0| 3| 66|
#> | 7| 6| 6| 66|
#> | 11| 1| 2| 66|
#> | 2| 2| 0| 65|
#> | 5| 7| 6| 64|
#> | 1| 11| 2| 63|
#> | 5| 8| 4| 63|
#> | 10| 0| 0| 63|
#> | 12| 0| 5| 63|
#> | 2| 3| 0| 62|
#> | 2| 10| 0| 62|
#> | 10| 1| 10| 61|
#> | 0| 5| 0| 60|
#> | 3| 0| 2| 60|