Hi Robert, I am extending uncertain retirement income with the addition of age-dependency. Currently, I have the following model, which works fine:
2 Markov shocks:
- persistent labor shock z1;
- permanent retirement shock (e.g., death of spouse) z2.
2 iid shocks:
- transitory labor shock e1;
- transitory retirement shock (e.g., health expenses) e2.
Based on discussion in the topic “Age-dependent health shocks” I introduce age-dependency to z2 as follows:
% Permanent retirement shock (death of spouse) z2 (age-dependent)
z2_grid=[1;0.5]; % 50% probability of a pension drop
Params.dj_1=Params.dj(21:101);
p_B_j = zeros(1,N_j); % hance that the drop remains forever
pi_z2_J = zeros(n_z(2),n_z(2),N_j);
for j=1:N_j
prob_j = [Params.dj_1(j),1-Params.dj_1(j);
p_B_j(j),1-p_B_j(j)];
pi_z2_J(:,:,j) = prob_j;
end
% Combine z1, z2 together
z_grid=[z1_grid; z2_grid];
pi_z = zeros(n_z(1)*n_z(2),n_z(1)*n_z(2),N_j);
for j=1:N_j
pi_z(:,:,j) = kron(pi_z2_J(:,:,j),pi_z1);
end
I think the code should be fine to some extent. However, I receive the following error when I try to solve the value function iteration:
tic;
[V, Policy]=ValueFnIter_Case1_FHorz(n_d,n_a,n_z,N_j,d_grid, a_grid, z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames, [], vfoptions);
toc
Test ValueFnIter
Warning: When using vfoptions.riskyasset you should also set vfoptions.refine_d (you do not have refine_d, and this is making codes way slower
than they should be)
> In ValueFnIter_Case1_FHorz_RiskyAsset (line 74)
In ValueFnIter_Case1_FHorz (line 535)
Error using CreateReturnFnMatrix_Case2_Disc_Par2e (line 358)
gpuArray/arrayfun encountered an issue while compiling 'PortfolioCoiceModel5_ReturnFn (line 7)'.
Error in ValueFnIter_Case1_FHorz_RiskyAsset_noa1_e_raw (line 34)
ReturnMatrix=CreateReturnFnMatrix_Case2_Disc_Par2e(ReturnFn, n_d, n_a, n_z, n_e, d_grid, a_grid, z_gridvals_J(:,:,N_j), e_gridvals_J(:,:,N_j), ReturnFnParamsVec);
Error in ValueFnIter_Case1_FHorz_RiskyAsset (line 80)
[VKron, PolicyKron]=ValueFnIter_Case1_FHorz_RiskyAsset_noa1_e_raw(n_d,n_a2,n_z,vfoptions.n_e,n_u, N_j, d_grid, a2_grid, z_gridvals_J, vfoptions.e_gridvals_J, u_grid, pi_z_J, vfoptions.pi_e_J, pi_u, ReturnFn, aprimeFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, aprimeFnParamNames, vfoptions);
Error in ValueFnIter_Case1_FHorz (line 535)
[V,Policy]=ValueFnIter_Case1_FHorz_RiskyAsset(n_d,n_a1,n_a2,n_z,vfoptions.n_u, N_j, d_grid, a1_grid, a2_grid, z_gridvals_J, vfoptions.u_grid, pi_z_J, vfoptions.pi_u, ReturnFn, vfoptions.aprimeFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions);
Caused by:
Unable to find function, variable, or class 'e' on the MATLAB Path. Make sure your search path includes the correct folders.
Related documentation
As you see, I did not yet introduce vfoptions.refine_d because I get another error (I will report it in topic ‘Riskyasset (portfolio-choice) now much faster with refine’).
Many thanks.