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.
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: 800,296 × 8
#> # Groups: id, ivars [5,607]
#> id month ivars value value_df value_df_sd bl_value_jump thres_inv_dfsd
#> <dbl> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 70201 0 agg_BS_… 1.52e5 NA 187. 0 2.33
#> 2 70201 1 agg_BS_… 1.52e5 -21.9 187. 0 2.33
#> 3 70201 2 agg_BS_… 1.52e5 -21.5 187. 0 2.33
#> 4 70201 3 agg_BS_… 1.52e5 -21.1 187. 0 2.33
#> 5 70201 4 agg_BS_… 1.52e5 -20.7 187. 0 2.33
#> 6 70201 5 agg_BS_… 1.52e5 -20.4 187. 0 2.33
#> 7 70201 6 agg_BS_… 1.52e5 -20.0 187. 0 2.33
#> 8 70201 7 agg_BS_… 1.52e5 -19.7 187. 0 2.33
#> 9 70201 8 agg_BS_… 1.52e5 -19.3 187. 0 2.33
#> 10 70201 9 agg_BS_… 1.52e5 -19.0 187. 0 2.33
#> # ℹ 800,286 more rows
#>
#> $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
#>
#> $tstm_invest
#> # A tibble: 8,414 × 11
#> 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
#> # ℹ 5 more variables: mth_inv_start <dbl>, mth_inv_end <dbl>,
#> # capital_prior <dbl>, capital_end <dbl>, capital_invest <dbl>
#>