HubbardSkinnerZeldes1994 replication

Hey Robert,

First, thank you so much for VFI-Toolkit! After several days trying to do VFI in python, I came across the toolkit and in an hour was up and running (at least with your introduction models). The toolkit has also brought me across to MATLAB, so apologies if my question reflects my naivety with the language more than anything…

I’d like to solve a simple buffer-stock model (ala Carroll). So, I’m particularly interested in your replication of Hubbard, Skinner, and Zeldes (as a more generalized version of Carroll), but it throws the error below:

Error using ValueFnIter_Case1_FHorz_PType
Too many input arguments.

Error in HubbardSkinnerZeldes1994_function (line 127)
[~, Policy]=ValueFnIter_Case1_FHorz_PType(0,n_a,n_z,N_j,N_i, 0, a_grid, z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames,
ReturnFnParamNames,vfoptions);

Error in HubbardSkinnerZeldes1994 (line 141)
[Table1row.(descriptivestr{:}), Table2temp, Table3temp,
LifeCycProfiles.(descriptivestr{:})]=HubbardSkinnerZeldes1994_function(Params,n_a,n_z,simoptions, PTypeDist);

I’m probably missing something simple, but any help would much be much appreciated.

Thank you again for all your work.

Thomas

Hi Thomas,

Update to the lastest copy of the replication (and toolkit) and it should work now.

When VFI Toolkit was updated to version 2 I updated all the examples, but didn’t have the heart to face updating all the replications :woozy_face:

I have now done the update of this replication :grin: (I only ran one calibration, but I am confident the rest should work fine. If there is any error message let me know).

[Half the replications use v2, but half are still on v1. They are gradually being moved over as people ask about them.]

1 Like

Got it. I thought that might be the case after reading your April 2020 post.

Thank you so much! I will update now and let you know how I get on. :sunglasses:

Hi again Robert,

I hope you’re having a good week. :slightly_smiling_face:

I’ve updated the toolkit and replication, but get a different error:

Undefined function ‘colon’ for input arguments of type ‘struct’.

Error in ValueFnIter_Case1_FHorz_PType (line 20)
for ii=2:N_i

Error in HubbardSkinnerZeldes1994_function (line 123)
[~, Policy]=ValueFnIter_Case1_FHorz_PType(0,n_a,n_z,N_j,Names_i, 0, a_grid, z_grid, pi_z, ReturnFn, Params,
DiscountFactorParamNames,vfoptions);

Error in HubbardSkinnerZeldes1994 (line 145)
[Table1row.(descriptivestr{:}), Table2temp, Table3temp,
LifeCycProfiles.(descriptivestr{:})]=HubbardSkinnerZeldes1994_function(Params,n_a,n_z,simoptions,
PTypeDistParamNames);

Any ideas on this one?

Cheers,
Thomas

1 Like

Fixed.

When I updated I was just running the HubbardSkinnerZeldes1994_function(), rather than the full thing that loops over this for different calibrations/setups [cause I am lazy and it was easier]. Hence I forgot to modify the main file to pass Names_i to this function.

2 Likes

Just FYI here is a code that implements Carroll (1997)

1 Like

Hi Dr. Kirby,

Thank you so much for your work on the VFI Toolkit! I was also attempting to run the HSZ1994 replication code, but I am getting an error when I try to run the function SimLifeCycleProfiles_FHorz_Case1_PType on line 205.

I checked the GitHub page but couldn’t find the function. I thought it would be under SimulateTimeSeries > FHorz, but I couldn’t find it there or elsewhere. This post suggests there may have been an update. Would you be willing to confirm that the function still exists?

SimLifeCycleProfiles=SimLifeCycleProfiles_FHorz_Case1_PType(InitialDist,PTypeDistParamNames,Policy, FnsToEvaluate,Params,0,n_a,n_z,N_j,Names_i,0,a_grid,z_grid,pi_z, simoptions);
Unrecognized function or variable ‘SimLifeCycleProfiles_FHorz_Case1_PType’.

which SimLifeCycleProfiles_FHorz_Case1_PType
‘SimLifeCycleProfiles_FHorz_Case1_PType’ not found.

2 Likes

I keep the examples and Intros updated, but tend not to update the replications so they occasionally fall behind (just too much work as running some of them takes ages).

I will take a look in the next week or so and let you know.

2 Likes

Related to this question about replication, I would like to add a related point:

The function SimLifeCycleProfiles_FHorz_Case1_PType simulates a panel of N households for T periods using the policy functions calculated in the backward iteration step and the transition matrix for the shock z. I am using this function in other projects and it is a bit slow.

Speeding it up is very much part of my to-do list for this year :grinning:

(it is slow because the level at which parallelization is being done is kind of stupid, needs rewriting from the ground up)

1 Like

My suggestion is to parallelize over households, but instead of using parfor (slow), use implicit parallelization aka vectorization

Another route is to use arrayfun on the gpu: Matworks has a great example of how to do a MonteCarlo simulation for the price of a stock. This might be trickier to implement, though

https://www.mathworks.com/help/parallel-computing/using-gpu-arrayfun-for-monte-carlo-simulations.html

Yeah, vectorized (whether gpu or cpu) is what I was thinking. That mathworks example is kind of stupid though as they just compare cpu to gpu, but don’t parallelize the cpu so of course the cpu loses badly.

They do it by having a function that does a single simulation, and then run that function in parallel (on gpu, in serial on cpu). I was thinking I should make the actual simulation itself parallel (and just write it all out as vectorized matrix operations). [Which is of course exactly what your first sentence is saying :smiley: ]

1 Like

Fro what I have seen, the key to get substantial speedup is to use arrayfun on the gpu. It seems that arrayfun on gpu compiles the code: you can see that the first time you run it is as fast as normal gpu, but the second time is super fast.

After all, arrayfun is what you use to evaluate the return function. I am not sure how to use it for simulation, so that’s why I thought the example of Monte Carlo simulation on the mathworks website would help.

1 Like

@Josh, the toolkit used to have the options of simulating the model to calculate the life-cycle profiles. It became clear that this is way too slow, and it is better to iterate the agent distribution. Hence “SimLifeCycleProfiles_FHorz_Case1_PType” was eliminated, and “LifeCycleProfiles_FHorz_Case1_PType” should be used in it’s place.

I have gone through the HSZ1994 replication codes now updating them for this. Requires some other minor changes (the LifeCycleProfiles requires the StationaryDist as an input, which was previously not needed).

The code did some stupid stuff manually calculating the aggregates. There are toolkit commands (AggVars and AllStats) that do this for you so I updated it to use those.

I pushed update to the github repo:

Update this and make sure you have latest toolkit (from github repo). Should work now. Let me know if there is still any error.
(I just ran until it started solving for the second parameter combo, didn’t let it finish, don’t think it will have a problem after this.)

PS. Unless you have a specific interest in the HSZ1994 model, you will be better off looking at the Intro to Life-Cycle Models to learn how to solve these models, that gets maintained up to the latest and greatest the toolkit can do, whereas replications are mostly rather dated.

3 Likes