Hi Robert, I set n_a(2)=11 just for convenience. I think Chen (2010) sets the number of points on the housing grid equal to 35. The grid for assets is complicated (see my post above) but he seems to set 60 points for owners (among which 10 are below zero) and 50 points for renters. However, he uses golden section search with interpolation for assets, so to replicate his results with the toolkit, which relies on pure discretization, I had to use at least 300 points (more would be better).
As @Shiki pointed out, Chen (2010) discretizes also the housing choice for renters (I am 90% sure on this. Not 100% since the Fortran code is complicated ). This is not needed thanks to the nice trick Robert has shown.
ValuesOnGrid=EvalFnOnAgentDist_ValuesOnGrid_FHorz_Case1()
gives the values of the FnsToEvaluate on the state-space grid (so in this model, on the grids on assets, housing, and exogenous shock). When calculating any statistic, say the mean, what happens internally is that first if calculates these āvalues on gridā and then combines those with the weights (the agent distribution) to get the statistics āso in case of the mean, it is calculated as values on grid summed according to the weights (total mass of weights is 1, so no need to divide by total as part of calculating the mean).
This is going to allow you to see the value of the FnsToEvaluate everywhere in the (discretized) state-space of the model.
Now I have the CPU array LoanToValueRatio with size [n_assets,n_housing,n_z,N_j]
This is a big array and I cannot display it in Matlab, but I can compute some summary:
min(LoanToValueRatio) = 0.000000
max(LoanToValueRatio) = 14.577259
Tot no. elements = 1529682.000000
How many NaNs = 282656.000000
How many 0s = 6147.000000
It seems that there are indeed many NaN values in LoanToValueRatio. A bit strangeā¦
This explains why AggVars.LoanToValueRatio.Mean is NaN
The NaNs were just because the formula evaluated to NaN when hprime=0 due to trying to divide by zero [formula was: (hprime>0)*(aprime<0)*abs(aprime/hprime) ]
Easiest solution, just use a conditional restriction so that you can get a version only for Homeowners, just set
simoptions.conditionalrestrictions.Homeowners=@(aprime,hprime,a,z) (hprime>0);
and you can then also simplify
FnsToEvaluate.LoanToValueRatio=@(aprime,hprime,a,z) (aprime<0)*abs(aprime/hprime);
[no need to include that hprime>0; note, if aprime>0 then the loan is zero]
I updated my version of Chen (2010) codes to incorporate all the things Alessandro mentions. I think the only substantial thing still missing is that I donāt renormalize the model for g (deterministic growth), so I am implicitly just using g=0 [and toolkit does not do generalized lorenz curves so donāt do Gini of financial wealth as some observations are negative]. I also included a Chen2010.pdf that describes the model more in line with how VFI Toolkit codes implement it (and fix some typos).
Hi @Shiki, I think you can now have a look at Robertās updated codes. He incorporated all my changes and he has the general equilibrium as well. In case anything is still not clear, feel free to ask!