Life cycle model does not work

Dear Robert,

Thank you for your providing such a useful code. I am an experienced matlab user. But I am new to VFI.
By accident, I found this website and I am trying to run your code and VFI.
To try, I started to run the life-cycle model. However, I had difficulty even model3 of the life cycle model. Labor supply seems reasonable, but the asset level is always zero for all ages. I change the parameters to test such as making 10 period model, changing the pension benefit, changing the utility function as log(c). But none of those changes worked. The asset level is alway equal to zero. Labor supply is reasonable. I am wondering why. Do you have any idea? Any hint might be helpful. Thank you very much.

best,

1 Like

By the way, this is the graph of the value function.

I just ran LifeCycleModel3.m and it seems to work fine. The four graphs that it creates are included below. I downloaded the current copy from github (GitHub - vfitoolkit/IntroToLifeCycleModels: Gradually build up a life-cycle model) to make sure I have the exact same LifeCycleModel3 as you.

I am trying to think of why they might be different. I cannot think of anything obvious. I ran it both on gpu and cpu and get same answer.

Could you please make sure you have the lastest version of VFI Toolkit and run it again. If it has the same problem could you please ‘save workplace’ in matlab and send me a copy of all the output: robertdkirkby@gmail.com

LifeCycleModel3_Fig1
LifeCycleModel3_Fig2
LifeCycleModel3_Fig3
LifeCycleModel3_Fig4

PS. What version of Matlab are you using? It might not run correctly on something like R2017, but should be fine with something like R2020.

Dear Robert,

Thank you very much for your quick reply. Also, I really appreciate for providing this software. This software seems very useful.

The current version of my Matlab is 2021a. I also tested on Matlab 2022a. The results are the same. Saving is always zero. I also downloaded the toolkit in the last week using ZIP. So I think that it is the version 2.0. Is there a way to check the version of the tool kit that I am currently using?

By reading all comments in this forum, I found a possible reason of my failure. Currently, I do not have NVIDA GPU. I have AMD GPU. So, I ordered the NVIDIA GPU but the GPU has not arrived yet. So I set CPU only in the option when I ran the program. My guess is that even if I set CPU only, some parts of the program might use GPU information.

I will let you know what will happen once I receive NVIDIA GPU and run the program again.

Again, thank you very much for providing such wonderful software.

best,
Hiro

Even just on the CPU the answer should be the same as the GPU. The only difference is that solving these on the GPU is much faster. (Some of the more advanced commands in VFI Toolkit require gpu, but most can be used on cpu or gpu.)

If you downloaded it last week then the toolkit is up-to-date, especially for these commands (I am doing some changes all the time, but nothing relevant to these).

Hopefully the gpu fixes things :slight_smile: Although I can’t think why it would.

I’m happy to look over the workspace if you save and email it to me.

Dear Rober,

The problem is now fixed after installing GPU. It works perfeclty.
Also, it is so fast compared with CPU only.
Please look at the attached file.

Now I will work on those life cycle models!
Again, thank you very much! https://www.dropbox.com/s/vki1eksy04cavg1/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202022-08-07%2017.12.12.png?dl=0

best,
Hiro

Glad it is working for you now. Who knows what happened first time round.

Hope you find the toolkit useful and if you have any further questions feel free to ask. Lot’s of things are documented, but plenty of things are not :smiley:

If you are interested in understanding why gpus are fast for this you might be interested in something I wrote about parallelization for Economics: Computing, especially GPUs, for Economists – Robert Kirkby
(essentially, they have thousands of weak processing cores, so good when you want to do something that is a ‘simple’ calculation, and you want to do it hundreds or thousands of times)

1 Like

Dear Robert,

Thank you for suggesting the link. I will read it.

By the way, when I ranthe life-cycle models, the most of the models worked.
But when I ran the model13.m, model22.m and model23.m, it has the following error:

I am wondering whether this is due to the fact that the memory of my GPU is just 2giga or other reasons. (The main memory size is 64 giga, although.) For example, do I need to install CUDA tool kit for running those programs on Matlab?


Error using SimPanelIndexes_FHorz_Case1 (line 258)
Unable to perform assignment because the size of the left side is 3-by-81 and the size of the right side is 2-by-81.

Error in SimPanelValues_FHorz_Case1 (line 130)
SimPanelIndexes=SimPanelIndexes_FHorz_Case1(InitialDist,PolicyIndexesKron,n_d,n_a,n_z,N_j,pi_z, simoptions);

Error in LifeCycleModel13 (line 179)
SimPanelValues=SimPanelValues_FHorz_Case1(InitialDist,Policy,FnsToEvaluate,[],Params,n_d,n_a,n_z,N_j,d_grid,a_grid,z_grid,pi_z, simoptions);


best,

Without CUDA, Matlab cannot use the GPU.

If you want to know if matlab can use the gpu, try running the code
rand(2,2,'gpuArray')
it should create a 2-by-2 matrix of ‘uniform[0,1] random variables’, and it creates it on the gpu (rather than on the cpu, which is what would happen if instead we did rand(2,2))

If matlab cannot find the gpu, then this command will throw an error telling you that the gpu could not be found.

That error you report is not due to the gpu. I will take a look at why it happened and get back to you.

Sorry, was an ‘typo’ in the simulate panel data command. I have fixed it. Thanks for bringing it to my attention.

If you update to the latest VFI Toolkit those should work now.

PS. If the gpu runs out of memory you will get an error that says something along the lines of ‘ran out of gpu memory when trying to create this matrix’ (I forget the exact message)

Hi Robert,

Thank you for fixing the program. I downloaded a new toolbox. Now all life-cycle models worked very well. For model16.m, I set
simoptions.numbersims=10^2
instead of
simoptions.numbersims=10^4
since it took so long time for my computer when I use 10^4 for the number of simulation.
Other than that, all life-cycle models worked very well. All models are very interesting. Thank you.

best,

The panel data simulations by default use parallel cpus. So roughly speaking if you get hold of a computer with twice as many cores you will halve the runtime. (In practice the speed improvement will be not quite that good, but close.)

I have seen papers using anything from 100 to 1 million simulations, depending on what they are trying to do with them.

If there is something about life-cycle models that you think is important but for which there is no example (other than having two endogenous states), let me know. I am always interested in ideas on how to improve things.

Glad you find it useful :smiley:

[gpu is not much use for simulating panel data, because the times periods for each individual time series depend on the previous time period, so the parallel cpu is faster]