Skip to contents

This function takes a dataframe of investment increments and calculates the unique investment durations based on certain thresholds. It returns two dataframes: one with the unique investment durations for each investment definition, and another with the unique investment dates for each household.

Usage

ffp_hfid_invest_unique_dura(
  df_invest_ivar_jump,
  it_thres_invest_mth_gap = 2,
  verbose = FALSE,
  verbose_detail = FALSE,
  it_verbose_detail_nrow = 100
)

Arguments

df_invest_ivar_jump

The dataframe of investment increments, output from ffp_hfid_invest_jump

it_thres_invest_mth_gap

The threshold for the month gap between investments to be merged as single investment

verbose

A logical value indicating whether to print verbose output

verbose_detail

A logical value indicating whether to print detailed verbose output

it_verbose_detail_nrow

The number of rows to print for detailed verbose output

Value

A list containing the following elements:

tstm_invest_ivar_dura

The output from the ffp_hfid_invest_unique_dura function.

tstm_invdates_uniq

The unique investment dates, not by asset.

See also

Used by vignette(s) ffv_invest_loan_bridge. Related issue(s): PrjThaiHFID-#32, PrjThaiHFID-#1.

Author

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

Examples

df <- tstm_asset_loan
fl_sd_ithres <- stats::qnorm(0.99)
it_thres_invest_mth_gap <- 2
df_invest_ivar_jump <- ffp_hfid_invest_jump(df, fl_sd_ithres = fl_sd_ithres)
ffp_hfid_invest_unique_dura(df_invest_ivar_jump, it_thres_invest_mth_gap = it_thres_invest_mth_gap)
#> $tstm_invest_ivar_dura
#> # A tibble: 15,587 × 8
#>    thres_inv_mgap thres_inv_dfsd    id ivars       hh_inv_asset_ctr hh_inv_ctr
#>             <dbl>          <dbl> <int> <chr>                  <int>      <int>
#>  1              2           2.33  1003 agg_BS_1011                1          1
#>  2              2           2.33  1003 agg_BS_1012                1          1
#>  3              2           2.33  1003 agg_BS_1021                1          1
#>  4              2           2.33  1003 agg_BS_1022                1          1
#>  5              2           2.33  1003 agg_BS_1023                1          1
#>  6              2           2.33  1003 agg_BS_1025                1          1
#>  7              2           2.33  1003 agg_BS_2011                1          1
#>  8              2           2.33  1003 agg_BS_2021                1          1
#>  9              2           2.33  1003 agg_BS_3011                1          2
#> 10              2           2.33  1003 agg_BS_3022                1          2
#> # ℹ 15,577 more rows
#> # ℹ 2 more variables: mth_inv_start <dbl>, mth_inv_end <dbl>
#> 
#> $tstm_invdates_uniq
#> # A tibble: 4,848 × 6
#> # Groups:   id [755]
#>    thres_inv_mgap thres_inv_dfsd    id hh_inv_ctr mth_inv_start mth_inv_end
#>             <dbl>          <dbl> <int>      <int>         <dbl>       <dbl>
#>  1              2           2.33  1003          1             1           1
#>  2              2           2.33  1003          2            16          16
#>  3              2           2.33  1031          1             9           9
#>  4              2           2.33  1031          2            71          71
#>  5              2           2.33  1031          3            80          80
#>  6              2           2.33  1031          4           154         154
#>  7              2           2.33  1046          1             1           1
#>  8              2           2.33  1046          2           120         120
#>  9              2           2.33  1059          1             5           5
#> 10              2           2.33  1059          2            16          16
#> # ℹ 4,838 more rows
#>