Replication of Guerrieri and Lorenzoni (2017)

Hi, I tried to run the replication of Guerrieri and Lorenzoni (2017) and I have found a few bugs/typos.

  1. If I run the code as it, I get the error
Error using load
Unable to find file or directory
'./PaperMaterials/replication-codes-for-Credit-Crises-2017-1f7cb32/inc_process.mat'.

This happens because the file inc_process.mat is not shared in the replication folder. To make the code work, I set OverwriteWithGL2017Grid=0

  1. In the main script we call the function HeteroAgentStationaryEqm_Case1 without the (optional) inputs vfoptions. I would suggest to add vfoptions and simoptions as explicit input arguments, if someone wants to play around with these flags (please read below)
  2. After passing vfoptions to HeteroAgentStationaryEqm_Case1, I set vfoptions.divideandconquer = 1 but I got the error that says this is not implemented. Is this because DC is not very useful in infinite horizon models?
Error using ValueFnIter_Case1 (line 516)
Not yet implemented DC1

After a few fixes, I managed to run the code to compute the initial stationary equilibrium, but I get this:

Current GE prices: 
	r:   0.0071 
Current aggregate variables: 
	A:   2.6708 
Current GeneralEqmEqns: 
	BondMarketClearence:  -0.0004 

p_eqm_index_initial =

   NaN

Calculating various equilibrium objects
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.

I think the error for fprintf has to do with the file path in Windows being different from Mac. It would be useful to use fullfile to enhance portability between different OS.
However, why is

p_eqm_index_initial =

   NaN

?

Thanks!

1 Like

It may be a month or two before I get a chance to fix this (have some papers that demand to be worked on).

1 Like

No problem, Robert! It’s not urgent

Hi Robert,

Could you please upload on the replication folder this file that is missing:

load ./PaperMaterials/replication-codes-for-Credit-Crises-2017-1f7cb32/inc_process.mat

That’s the only thing that is really needed. The other observations in my previous post above are very minor :slight_smile:

Thank you so much!

1 Like

inc_process.mat comes from the original materials of GL2017. I have added a copy to the repo:

2 Likes

Awesome, thanks!
One quick fix:
(1) please change line 148 from

load ./PaperMaterials/replication-codes-for-Credit-Crises-2017-1f7cb32/inc_process.mat

to

load inc_process.mat

(2) Create empty folder SavedOutput. This is needed for line

save ./SavedOutput/GuerrieriLorenzoni2017_initial.mat Params p_eqm_initial p_eqm_index_initial MarketClearance_initial n_d n_a n_z

otherwise the code gives an error message. Moreover, the save command ./ seems OS-specific (i.e. might work only on linux/mac but not on Windows, not sure)

1 Like

I made change (1).

I am not going to make change (2). I think that the user having to create subfolders in which to save things is acceptable. If I include them in the repo it makes the files all a bit messier and harder to understand.

1 Like

Working on cleaning up the GL2017 replication just now.

Divide-and-conquer is not implemented for infinite-horizon just because I haven’t gotten round to it yet :stuck_out_tongue: I kind of expect the runtime gain to be pretty meager for this specific case (it is implemented for the transition paths in inf horizon, just not standard value fn problems with one endo state and hence not stationary eqm)

1 Like

Thanks! However, for an infinite horizon problem with static d variables like this one, the refine algorithm should help quite a bit. Is it always imposed as a default option, correct? So no need to specify it anymore as part of the vfoptions structure?

I have another question on Guerrieri and Lorenzoni. The benchmark model is relatively simple since it is a Huggett model with endogenous labor supply and an ad-hoc borrowing constraint which becomes tighter in a crisis. But they have an extended model with durable goods and other complications. Did you attempt to replicate that part as well?

Yes, refine is on by default (for stationary eqm; it is not used for transition path). And while I’m overhauling it I plan to turn on divideandconquer for the transition path.

1 Like

Just pushed a fix to about 80% of the replication, updating it to v2.3 of toolkit and it works nice and cleanly.

Two things left that I will hopefully finish updating in near future: I need to fix Figure 6 which uses SimPanelValues, and I need to fix the ā€˜durable goods’ extension. Everything else should just work.

While I was there I updated infinite horizon value fn so now if you have one endogenous state and set vfoptions.divideandconquer=1 it will just ignore this and print a warning that it is ignoring it (so you can easily have it on for transition paths, where it is implemented, and not have to turn it off for inf-horz value fn in stationary eqm where it is not yet implemented).

1 Like

Did Figure 6 with the SimPanelValues, turned out much easier to fix than I expected.

Durable goods will take a while. I think there is a better way to solve it nowadays with the toolkit features so I want to try that out, but likely to be a month or two.

1 Like

This is fantastic. I was wondering if there is a way to solve analytically for the static labor supply d as a function of (a',a,z). I managed to obtain d as a function of consumption c and productivity z, but this does not help with the toolkit setup, I guess.

I know that setting up a grid for d is more general, but it really adds to the computational time. This is not a concern in this simple model, but it can be in more complicated ones

(1) When computing the steady-state of the model, I get many times the warning

Warning: vfoptions.divideandconquer=1 has not yet been implemented for length(n_a)=1 in infinite horizon, so just
ignoring it (and doing vfoptions.divideandconquer=0)

This is intended, as you explained in your post above. However, it really clutters the output window, so in my code I set vfoptions.divideandconquer=0 at the beginning, for the initial and final steady-state. Then I set vfoptions.divideandconquer=1; before doing the transition.

(2) The grid for the GE price r has 1000 points. Isn’t it a bit too much?

I was wondering if there is a way to solve analytically for the static labor supply d as a function of (a',a,z). I managed to obtain d as a function of consumption c and productivity z, but this does not help with the toolkit setup, I guess.
This definitely makes things faster. Not sure if it is possible or not in this model (I’ve not tried). Once you obtain d as a function of consumption c and productivity z maybe you substitute this back into the budget constraint for c and then have a budget constraint with only d, aprime, a, z, and from this you can get the closed form eqn you want. As I said, I’ve not tried for this model, but it definitely makes codes faster when it is possible.

(2) The grid for the GE price r has 1000 points. Isn’t it a bit too much?
Yes. But I like to be a bit ā€˜overkill’ for replications. (In an example code I would use way less.)

1 Like

Thanks for your answers, Robert! I found a small typo in the pdf of the replication, available here: vfitoolkit-matlab-replication/GuerrieriLorenzoni2017/GuerrieriLorenzoni2017.pdf at master Ā· vfitoolkit/vfitoolkit-matlab-replication Ā· GitHub

In the second paragraph, you write ā€œThe large differences in B and phiā€, but then phi shows up in the table as the borrowing limit but not in the equations. In the model equations, you call the borrowing limit psi, but psi is also used to denote the leisure weight in utility

Fixed the typo. Thanks!

1 Like

Thanks for your answer to (1).

Given the specific utility function used by Guerrieri and Lorenzoni (2017),

u(c,n) = \frac{c^{1-\gamma}}{1-\gamma} + \psi \frac{(1-n)^{1-\eta}}{1-\eta}

it is not possible to solve analytically for d(a',a,z). I can derive analytically labor supply n (our d variable) as a function of c and z as follows

n(c,z) = 1- (\frac{\psi}{z})^{\frac{1}{\eta}} c^{\frac{\gamma}{\eta}}
where
c = a+zn - \frac{a'}{1+r}
but once you substitute the budget constraint to replace c, you obtain a nonlinear equation of the form
F(n,a',a,z)=0
which cannot be solved analytically for n. If you change the utility function and you take the Cobb-Douglas functional form used e.g. by Conesa and Krueger (RED, 1999), then you can find a closed form solution for n (or d).

Suggestions for computation. With the toolkit, the only way is then to discretize also labor supply, as done in the GL 2017 replication. If you write your own code, you have a couple of alternative methods:

  1. Discretize a and a' and then for each (a',a) pair, solve the nonlinear equation F(n,a',a,z)=0 using a rootfinding algorithm like bisection
  2. Instead of maximizing over a', use c as a choice variable. Then given c, you obtain d analytically and a' follows reasidually from the budget constraint. However, this second approach requires then interpolating the next-period value function over a', since the a' implied by the budget constraint is unlikely to be on the grid for assets.

Question. Approach (1) is clearly not feasible with the toolkit. Can the toolkit deal with (2), after minor adaptations? I ask this since nowadays the toolkit can do linear interpolation :slight_smile:

Note: the formula derived above for n as a function of c and z is valid only for interior solutions n>0. To take into account corner solution, it should be written as

n(c,z) = \max ( 0, \ 1- (\frac{\psi}{z})^{\frac{1}{\eta}} c^{\frac{\gamma}{\eta}} )

1 Like

Cool! Good to know why closed-form exists for Conesa & Krueger (1999) but not for Guerrieri & Lorenzoni (2017). Tricks with utility fns :slight_smile: [the Conesa & Krueger (1999) replication codes do not exploit this]

Actually, I think (1) is very close to refine. Details differ, but same kind of concept; for refine you don’t route-find you just choose d on grid as the best grid point given (a’,a,z), and it is max of return fn, rather than the solution to an FOC. But that is largely the same thing, just different in small details. Plus refine in infinite horizon gets ā€˜reused’ at every iteration, but you could do the same with the (1).

I am not so sure that (2) is possible with toolkit as it currently works. Maybe you can use ā€˜expasset’, so aprime(d,a), and then have d be the consumption? You would then set aprime(d,a) as being the next period assets based on consumption and current assets, and this would linearly interpolate onto the grid. This should run, but I don’t know if it will be good or not. I think with the way the toolkit currently operates this is likely the closest to (2) that you can do, just not sure if it is better or worse that standard approach. I think any advantage/disadvantage would come from needing less/more grid points for consumption than you use for aprime; I guess if the range of consumption is smaller than the range of aprime, then it might be faster to take this approach.
[I’ve been thinking recently about doing something similar solving KMV2018 using expasset for the illiquid asset and having d be ā€˜change in illiquid assets’. So I should have a better feeling for how well/poorly it works in the near future.]

PS. refine does not work with divide-and-conquer because of how I exploit the monotonicity conditional on d, and so I need to do all d to have the conditional on d which means I cannot refine d out beforehand.

1 Like

Thanks for the detailed answer!

Regarding Kaplan, Moll and Violante (2018):
I’m not very familiar with the HANK literature, but there is somewhere a toolkit replication of a model with two endogenous state variables, financial assets and housing, this is Chen (2010). Isn’t this similar to KMV (2018)? One can interpret housing as the illiquid assets. Is the housing block of KMV (2018) more challenging than Chen (2010)? Then KMV (2018) has all the new-keyensian frictions but that shouldn’t pose a big computational difficulty