Skip to contents

This function removes duplicate loans from a loans panel dataset based on a specified lender variable and loan dates, and combines loan size from loans with the same lender and dates, and generates aggregate monthly compounding interest rates.

Usage

ffp_hfid_loan_non_duplicate(
  df_loans_panel,
  svr_lender_var = "forinfm4",
  svr_principal_interest_sum = "bm6b",
  svr_principal = "bf5klm_bm6h_joint",
  svr_principal_last = "bm6h",
  verbose = FALSE,
  verbose_detail = FALSE,
  it_verbose_detail_nrow = 100
)

Arguments

df_loans_panel

The loans panel dataset, unit of observation is loan in each month of loan life.

svr_lender_var

The variable name of the lender variable used to identify duplicate loans. Default is "forinfm4". Can change this to change the definition of what an identical lender is.

svr_principal_interest_sum

The variable name to be summed for principal and interest in the dataset.

svr_principal

The variable name for the loan principal in the dataset.

svr_principal_last

The variable name for the amount of principal repaid in the last month of loan.

verbose

Logical indicating whether to print progress messages. Default is FALSE.

verbose_detail

Logical indicating whether to print detailed progress messages. Default is FALSE.

it_verbose_detail_nrow

The number of rows to print when verbose_detail is TRUE. Default is 100.

Value

A list containing the following elements:

tstm_loans_pn

Each loan own row, interest rate, size, duration.

tstm_loans_pn_nd

Each row a unique loan by lender type and dates, with aggregated loan size from loans with the same lender and dates.

See also

Used by vignette(s) ffv_invest_loan_bridge (and re-called inline by ffv_invest_return_bridge). Related issue(s): PrjThaiHFID-#32.

Author

Fan Wang, http://fanwangecon.github.io

Examples

tstm_loans_panel <- PrjThaiHFID::tstm_loans_panel 
ls_return <- ffp_hfid_loan_non_duplicate(tstm_loans_panel)
print(ls_return)
#> $tstm_loans_pn
#> # A tibble: 20,943 × 10
#>    hhid_Num hh_loan_id hh_loan_id_nd loan_start loan_end number_indi_loan
#>       <int>      <int>         <int>      <dbl>    <dbl>            <int>
#>  1     1003          1             1          1        8                2
#>  2     1003          2             2          1       10                1
#>  3     1003          3             1          1        8                2
#>  4     1003          4             3          2        3                1
#>  5     1003          5             4          3        8                1
#>  6     1003          6             5          9       26                1
#>  7     1003          7             7         10       26                1
#>  8     1003          8             6         10       22                1
#>  9     1003          9             8         11       18                1
#> 10     1003         10             9         12       26                1
#> # ℹ 20,933 more rows
#> # ℹ 4 more variables: forinfm4 <chr>, loan_principal_interest <dbl>,
#> #   loan_principal <dbl>, loan_principal_last <dbl>
#> 
#> $tstm_loans_pn_nd
#> # A tibble: 19,587 × 10
#>    hhid_Num hh_loan_id_nd loan_start loan_end number_indi_loan forinfm4       
#>       <int>         <int>      <dbl>    <dbl>            <int> <chr>          
#>  1     1003             1          1        8                2 Informal       
#>  2     1003             2          1       10                1 Quasi-formal   
#>  3     1003             3          2        3                1 Informal       
#>  4     1003             4          3        8                1 Informal       
#>  5     1003             5          9       26                1 Informal       
#>  6     1003             6         10       22                1 Quasi-formal   
#>  7     1003             7         10       26                1 Informal       
#>  8     1003             8         11       18                1 BAAC-Commercial
#>  9     1003             9         12       26                1 Informal       
#> 10     1003            10         16       29                1 Quasi-formal   
#> # ℹ 19,577 more rows
#> # ℹ 4 more variables: loan_principal_interest <dbl>, loan_principal <dbl>,
#> #   loan_principal_last <dbl>, loan_interest_monthly <dbl>
#>