Hi,
I’ve got a question related to the toolkit by Thomas Winberry, published with "A Method for Solving and Estimating Heterogeneous Agent Macro Models "(Quantitative Economics | The Econometric Society). I am writing with a question related to the code in the setParamers.m file, in the context of an error that I am getting.
What I’ve done to the code is changed it to include 12 entries of vEpsilonGrid, making mEpsilonTransition a 12 by 12 matrix and EpsilonInvariant a 12-element vector, in the setParameters.m file. I chose aggEmployment as implied from the invariant distribution and changed nEpsilon to 12; other than that, I have not changed anything in this file. Please see the input below (starts in line 22):
vEpsilonGrid = [0; 0; 0.232207978; 0.411700079; 0.504556796; 0.603717578; 0.738998498; 0.868901935; 1.014524167; 1.17728816; 1.433918183; 3.014186627];
aggEmployment = (1-0.0833-0.0833);
mEpsilonTransition = [0.78 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02; 0.02 0.18 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08 0.08; ...
0.02 0.08 0.41 0.24 0.14 0.04 0.03 0.02 0.01 0 0.01 0; 0.02 0.08 0.21 0.22 0.2 0.12 0.07 0.04 0.02 0.01 0.01 0; ...
0.02 0.08 0.06 0.1 0.33 0.22 0.11 0.04 0.02 0 0.01 0.01; 0.02 0.08 0.06 0.1 0.17 0.15 0.18 0.11 0.06 0.03 0.02 0.02; ...
0.02 0.08 0.05 0.04 0.09 0.21 0.14 0.2 0.1 0.04 0.02 0.01; 0.02 0.08 0.03 0.07 0.04 0.07 0.19 0.2 0.16 0.09 0.03 0.02; ...
0.02 0.08 0.02 0.02 0.02 0.05 0.1 0.18 0.19 0.22 0.06 0.04; 0.02 0.08 0.02 0 0.02 0.02 0.03 0.07 0.2 0.26 0.22 0.06; ...
0.02 0.08 0.01 0 0.01 0.03 0.03 0.03 0.09 0.2 0.31 0.19; 0.02 0.08 0 0.01 0 0 0.02 0.02 0.03 0.07 0.2 0.55];
vEpsilonInvariant = [0.0833; 0.0833; 0.0769; 0.0726; 0.0946; 0.0858; 0.0844; 0.0848; 0.0823; 0.0854; 0.0829; 0.0838];
In order to account for the fact that the gird has now 12 entries, not 2 (and the transition matrix is 12 by 12, not 2 by 2), I also changed the following in the firstOrderDynamics_polynomials_steadyState.m, to account for the fact that there are 12 elements now, and adopted the EpsilonInvariant entires that I use, instead of aggEmployment and (1-aggEmployment) (line 69):
aggregateCapital = (1 - mHat(1,1)) * (0.0842) * mMoments(1,1) + (1 - mHat(2,1)) * 0.0816 * mMoments(2,1) + (1 - mHat(3,1)) * 0.0833 * mMoments(3,1) + (1 - mHat(4,1)) * 0.0841 * mMoments(4,1) + ...
(1 - mHat(5,1)) * 0.0834 * mMoments(5,1) + (1 - mHat(6,1)) * 0.0842 * mMoments(6,1) + (1 - mHat(7,1)) * 0.0818 * mMoments(7,1) + (1 - mHat(8,1)) * 0.0850 * mMoments(8,1) + (1 - mHat(9,1)) * 0.0825 * mMoments(9,1) + ...
(1 - mHat(10,1)) * 0.0832 * mMoments(10,1) + (1 - mHat(11,1)) * 0.0833 * mMoments(11,1) + (1 - mHat(12,1)) * 0.0833 * mMoments(12,1);
I also changed the line 145 of computeMCResidualHistogram.m, to account for the 12 elements:
residual = capital - sum(vAssetsGridFine' .* (mHistogram(1,:) + mHistogram(2,:)+mHistogram(3,:)+mHistogram(4,:)+mHistogram(5,:)+mHistogram(6,:)+mHistogram(7,:))+mHistogram(8,:)+mHistogram(9,:)+mHistogram(10,:)+mHistogram(11,:)+mHistogram(12,:));
Finally, I also changed line 71 in coreSteadyState.m accordingly:
mHatHistogram = [mHistogram(1,1) / sum(mHistogram(1,:));mHistogram(2,1) / sum(mHistogram(2,:));mHistogram(3,1) / sum(mHistogram(3,:));mHistogram(4,1) / sum(mHistogram(4,:));mHistogram(5,1) / sum(mHistogram(5,:));mHistogram(6,1) / sum(mHistogram(6,:));mHistogram(7,1) / sum(mHistogram(7,:));mHistogram(8,1) / sum(mHistogram(8,:));mHistogram(9,1) / sum(mHistogram(9,:));mHistogram(10,1) / sum(Histogram(10,:));mHistogram(11,1) / sum(Histogram(11,:));mHistogram(12,1) / sum(Histogram(12,:))];
Once I run SteadyState.m and get a computation of an initial guess from the histogram , I get the following:
Done! Time to compute: 17.45 seconds
Unrecognized function or variable ‘Histogram’.
Error in coreSteadyState (line 71)
mHatHistogram = [mHistogram(1,1) / sum(mHistogram(1,:));mHistogram(2,1) / sum(mHistogram(2,:));mHistogram(3,1) / sum(mHistogram(3,:));mHistogram(4,1) / sum(mHistogram(4,:));mHistogram(5,1) / sum(mHistogram(5,:));mHistogram(6,1) / sum(mHistogram(6,:));mHistogram(7,1) / sum(mHistogram(7,:));mHistogram(8,1) / sum(mHistogram(8,:));mHistogram(9,1) / sum(mHistogram(9,:));mHistogram(10,1) / sum(Histogram(10,:));mHistogram(11,1) / sum(Histogram(11,:));mHistogram(12,1) / sum(Histogram(12,:))];
Error in steadyState (line 21)
coreSteadyState;
Once I’ve done the same by analogy for a 4 by 4 transition matrix (and a grid with 4 entries), there was no error. I am wondering if the error occurs due to a wrong setup of the parameters below in the setParameters.m file, given that the matrix is now greater? After numerous attempts I believe the problem is with the parameters below, not with the code that I believe to have changed appropriately. Is there something specific about the 12 by 12 matrix that makes the error occur? Please see the setParameters.m file extract below where I guess the mistake is. I’ve been experimenting with different values of nAssets, nAssetsFine, assetsMax, nAssetsFine, nMeasure, nAssetsQuadrature, maxIterations, tolerance and dampening, however, I keep getting the same error.
% Order of approximation
nEpsilon = 12;
nAssets = 25; % number of gridpoints in spline approximation or polynomials in polynomial approximation
nState = nEpsilon * nAssets;
% Bounds on grid space
kRepSS = ((aalpha * (aggEmployment ^ (1 - aalpha))) / ((1 / bbeta) - (1 - ddelta))) ^ (1 / (1 - aalpha));
assetsMin = aaBar; assetsMax = 3 * kRepSS;
% Finer grid for analyzing policy functions
nAssetsFine = 100;
nStateFine = nEpsilon * nAssetsFine;
% Approximation of distribution
nMeasure = 200;
nAssetsQuadrature = 12;
nStateQuadrature = nEpsilon * nAssetsQuadrature;
nMeasureCoefficients = nEpsilon * nMeasure;
% Iteration on individual decisions
maxIterations = 2e5;
tolerance = 1e-10;
dampening = .95;
In sum, I would be most thankful for any guidance on how the parameters above could be changed so that the code runs with a 12 by 12 matrix, if that’s the source of the problem. Has anybody encountered a similar issue? I am using Dynare 5.3, so I am making use of the codes kindly adjusted by J. Pfeifer (GitHub - JohannesPfeifer/winberryAlgorithmCodes: Dynare codes for A Method for Solving and Estimating Heterogeneous Agent Macro Models). Thanks a lot in advance.