This function serves as a gateway function for the ffp_hfid_invest package. It takes in various parameters and performs a series of calculations to generate investment-related outputs.
Usage
ffp_hfid_invest_gateway(
df_asset,
fl_sd_ithres = stats::qnorm(0.99),
it_thres_invest_mth_gap = 2,
svr_hhid = "id",
svr_time = "month",
verbose = FALSE,
verbose_detail = FALSE,
it_verbose_detail_nrow = 100
)Arguments
- df_asset
The input data frame containing asset information.
- fl_sd_ithres
The threshold value for the standard deviation of investment jumps. Default is set to 0.99 quantile of the standard normal distribution.
- it_thres_invest_mth_gap
The threshold value for the minimum number of months between investments to be merged as single investment. Default is set to 2.
- svr_hhid
The name of the column in df_asset that represents the household ID. Default is set to "id".
- svr_time
The name of the column in df_asset that represents the time variable. Default is set to "month".
- verbose
Logical value indicating whether to display progress messages. Default is set to FALSE.
- verbose_detail
Logical value indicating whether to display detailed progress messages. Default is set to FALSE.
- it_verbose_detail_nrow
The number of rows to display in detailed progress messages. Default is set to 100.
Value
A list containing the following elements:
- tstm_invest_ivar_jump
The output from the ffp_hfid_invest_jump function.
- tstm_invest_ivar_dura
The output from the ffp_hfid_invest_unique_dura function.
- tstm_invdates_uniq
The unique investment dates, not by asset.
- tstm_invest
The combined investment information from tstm_invest_ivar_jump and tstm_invest_ivar_dura.
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
ls_return <- ffp_hfid_invest_gateway(
df, fl_sd_ithres = fl_sd_ithres, it_thres_invest_mth_gap=it_thres_invest_mth_gap
)
print(ls_return)
#> $tstm_invest_ivar_jump
#> # A tibble: 1,352,616 × 8
#> # Groups: id, ivars [9,492]
#> id month ivars value value_df value_df_sd bl_value_jump thres_inv_dfsd
#> <int> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1003 0 agg_BS_… 1.11e5 NA 11896. 0 2.33
#> 2 1003 1 agg_BS_… 1.67e5 55691. 11896. 1 2.33
#> 3 1003 2 agg_BS_… 1.64e5 -2352. 11896. 0 2.33
#> 4 1003 3 agg_BS_… 1.78e5 13788. 11896. 0 2.33
#> 5 1003 4 agg_BS_… 1.75e5 -2676. 11896. 0 2.33
#> 6 1003 5 agg_BS_… 1.73e5 -2628. 11896. 0 2.33
#> 7 1003 6 agg_BS_… 1.70e5 -2580. 11896. 0 2.33
#> 8 1003 7 agg_BS_… 1.68e5 -2534. 11896. 0 2.33
#> 9 1003 8 agg_BS_… 1.61e5 -6358. 11896. 0 2.33
#> 10 1003 9 agg_BS_… 1.59e5 -2344. 11896. 0 2.33
#> # ℹ 1,352,606 more rows
#>
#> $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
#>
#> $tstm_invest
#> # A tibble: 15,587 × 11
#> 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
#> # ℹ 5 more variables: mth_inv_start <dbl>, mth_inv_end <dbl>,
#> # capital_prior <dbl>, capital_end <dbl>, capital_invest <dbl>
#>