Life cycle profiles, permanent types

I tried to run the life-cycle example model 25 (two types: patient and impatient), available here: IntroToLifeCycleModels/LifeCycleModel25.m at main · vfitoolkit/IntroToLifeCycleModels · GitHub

and everything is fine (and very fast!) until the code reaches line 225

AgeConditionalStats=LifeCycleProfiles_FHorz_Case1_PType(StationaryDist, Policy, FnsToEvaluate, Params,n_d,n_a,n_z,N_j,Names_i,d_grid, a_grid, z_grid, simoptions);

and then returns an error:

Error using gpuArray/reshape
Number of elements must not change. Use as one of the size inputs to automatically calculate
the appropriate size for that dimension.

Error in EvalFnOnAgentDist_ValuesOnGrid_FHorz_subfn (line 186)
Values(:,jj)=reshape(EvalFnOnAgentDist_Grid_Case1(FnsToEvaluate{ff}, FnToEvaluateParamsVec,reshape(PolicyValues(:,jj),[n_a,n_z,l_d+l_a]),n_d,n_a,n_z,a_grid,z_grid,2),[N_a*N_z,1]);

Error in LifeCycleProfiles_FHorz_Case1_PType (line 388)
ValuesOnGrid_kkii=EvalFnOnAgentDist_ValuesOnGrid_FHorz_subfn(PolicyValues_temp, FnsToEvaluate_iikk, Parameters_temp, FnsToEvaluateParamNames_ii, n_d_temp, n_a_temp, n_z_temp, N_j_temp, a_grid_temp, z_grid_temp,simoptions_temp);

Error in LifeCycleModel25 (line 225)
AgeConditionalStats=LifeCycleProfiles_FHorz_Case1_PType(StationaryDist, Policy, FnsToEvaluate, Params,n_d,n_a,n_z,N_j,Names_i,d_grid, a_grid, z_grid, simoptions);

I’ve found another error related to models with semi-exogenous shocks. Now I consider a setup with two semi-exogenous shocks, two decision variables that affect the semi-exo shocks, no other decision variable and no z shocks. The relevant variables for the semi-exo transition function are

lm,lf,lmprime,lfprime,sm,sf

where semiz = [lm;lf] and d=[sm,sf]

There are no PT in this case. There is a problem with the command for the stationary distribution:

StationaryDist=StationaryDist_FHorz_Case1(jequaloneDist,AgeWeightsParamNames,Policy,n_d,n_a,n_z,N_j,pi_z,Params,simoptions);

It does not find the first parameter, which means that it does not recognize the second decision variable. I set the options

%no of decision d variables relevant for semi-exo z=[lm;lf]. We have d=[sm,sf]
vfoptions.numd_semiz = 2;
simoptions.numd_semiz = vfoptions.numd_semiz;

which makes the VFI work but not the stationary distribution

Thanks again for looking into this!

Life-cycle model example 25 should be fixed now.

I am going to spend all next week reworking these FnsToEvaluate commands. There is a lot of room to improve them and make them faster (and now agent distributions are so fast it is worth giving them a little love)

Can you please send me code on the semi-exo? I will get it working [when I first coded semi-exo it just assumed only one d variable and it was the last one, so I need to change this]

1 Like

The code is in our shared Dropbox, Codes\v2
It is the model with couples, so two decision variables (search efforts of the two members) that affect the semi-exo shocks

Thanks!

agent dist with semi exogenous shocks now allows that there is more than one decision variable that determines the semi-exog shock transitions, and that there are no other decision variables

1 Like

Thanks a lot! I downloaded the new codes but I still get an error when the code calls the function to compute the stationary distribution (same line as before). I have sent you an email.

Sync failure. Should work now.

1 Like

Thanks! With the updated codes the stationary distributions works and is very fast. The command LifeCycleProfiles_FHorz_Case1_PType (in the model with singles) still returns the same error though

Are you still talking about Life-Cycle Model 25? Or a different one?

I just ran 25 and it worked fine. If it is this one can you please copy-paste the error message?

1 Like

It is the code in our shared Dropbox, v1. When I run main_v1.m, I get the following mistake at the end.

The line is

AgeConditionalStats=LifeCycleProfiles_FHorz_Case1_PType(StationaryDist,Policy,FnsToEvaluate,Params,n_d,n_a,n_z,N_j,Names_i,d_grid,a_grid,z_grid,simoptions);

and the error message is:

Error using gpuArray/reshape
Number of elements must not change. Use as one of the size inputs to
automatically calculate the appropriate size for that dimension.

Error in LifeCycleProfiles_FHorz_Case1_PType (line 941)
StationaryDist.(Names_i{ii})=reshape(StationaryDist.(Names_i{ii}),[N_a_temp*N_z_temp,N_j_temp]);

Error in main_v1 (line 199)
AgeConditionalStats=LifeCycleProfiles_FHorz_Case1_PType(StationaryDist,Policy,FnsToEvaluate,Params,n_d,n_a,n_z,N_j,Names_i,d_grid,a_grid,z_grid,simoptions);

Should work now (life-cycle profiles couldn’t handle that there were semi-exo but no exo states, now it can)

1 Like