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.

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: 8,414 × 8
#>    thres_inv_mgap thres_inv_dfsd    id ivars       hh_inv_asset_ctr hh_inv_ctr
#>             <dbl>          <dbl> <dbl> <chr>                  <int>      <int>
#>  1              2           2.33 70201 agg_BS_1011                1          1
#>  2              2           2.33 70201 agg_BS_3011                1          1
#>  3              2           2.33 70202 agg_BS_1011                1          1
#>  4              2           2.33 70202 agg_BS_1011                2          2
#>  5              2           2.33 70202 agg_BS_1011                3          3
#>  6              2           2.33 70202 agg_BS_1011                4          4
#>  7              2           2.33 70202 agg_BS_1011                5          5
#>  8              2           2.33 70202 agg_BS_1011                6          7
#>  9              2           2.33 70202 agg_BS_1012                1          8
#> 10              2           2.33 70202 agg_BS_1021                1          8
#> # ℹ 8,404 more rows
#> # ℹ 2 more variables: mth_inv_start <dbl>, mth_inv_end <dbl>
#> 
#> $tstm_invdates_uniq
#> # A tibble: 3,744 × 6
#> # Groups:   id [754]
#>    thres_inv_mgap thres_inv_dfsd    id hh_inv_ctr mth_inv_start mth_inv_end
#>             <dbl>          <dbl> <dbl>      <int>         <dbl>       <dbl>
#>  1              2           2.33 70201          1            18          18
#>  2              2           2.33 70202          1            31          31
#>  3              2           2.33 70202          2            63          63
#>  4              2           2.33 70202          3           102         102
#>  5              2           2.33 70202          4           111         111
#>  6              2           2.33 70202          5           123         123
#>  7              2           2.33 70202          6           147         147
#>  8              2           2.33 70202          7           147         148
#>  9              2           2.33 70202          8           148         148
#> 10              2           2.33 70203          1            28          28
#> # ℹ 3,734 more rows
#>