-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcomputeLMCResidualHistogram.m
106 lines (82 loc) · 4.52 KB
/
computeLMCResidualHistogram.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function [residual,vCoefficientsOptional,vCapitalCoefficientsOptional,vCapitalAdjustOptional,...
vCapitalConstrainedOptional,vCutoffOptional,vHistogramOptional] = computeLMCResidualHistogram(wage);
% Computes the residual of the labor market clearing condition, approximating the distribution
% using a histogram; used to compute initial guess of parametric family
%
% Inputs
% (1) wage: candidate wage
%
% Outputs
% (1) residual: residual of market clearing condition (to use in root finder)
% (2) (optional) CoefficientsOptional: coefficients on value function
% (3) (optional) vCapitalCoefficientsOptional: coefficients on adjust capital decision
% (4) (optional) vCapitalAdjustOptional: capital decision if adjust, along histogram grid
% (5) (optional) vCapitalConstrainedOptional: capital decision if not adjust, along histogram grid
% (6) (optional) vCutoffOptional: adjustment cutoff, along histogram grid
%
% Thomas Winberry, February 14th, 2018
% Declare global variables used in this function
global mStateGrid ttheta nnu ddelta mStatePoly vStatePolySquared tolerance maxIterations nState mFinePoly mFineGrid ...
aaUpper aaLower capitalMin capitalMax nShocks aProdPrimeFinePoly nStateFine nProd nCapital bbeta dampening ...
nProdFine nCapitalFine vShocksWeights ppsiCapital nSS
%----------------------------------------------------------------
% Compute value function
%----------------------------------------------------------------
% Compute labor demand over the grid (independent of value function, but depends on wage)
global vLaborDemandGrid vProfitGrid
vLaborDemandGrid = ((exp(mStateGrid(:,1)) .* (mStateGrid(:,2) .^ ttheta) * nnu) / wage) .^ (1 / (1 - nnu));
vProfitGrid = exp(mStateGrid(:,1)) .* (mStateGrid(:,2) .^ ttheta) .* (vLaborDemandGrid .^ nnu) - wage * vLaborDemandGrid;
% Initialize value function
vInitGrid = vProfitGrid + (1 - ddelta) * mStateGrid(:,2);
vCoefficients = sum(mStatePoly' .* (ones(nState,1) * vInitGrid'),2);
vCoefficients = vCoefficients ./ vStatePolySquared;
% Initialize iteration
err = 100;
iterations = 1;
t0 = tic;
% Do value function iteration
while err > tolerance && iterations <= maxIterations
[vCoefficientsNew,vCapitalAdjust] = updateCoefficients(vCoefficients);
err = max(abs(vCoefficientsNew - vCoefficients));
iterations = iterations + 1;
vCoefficients = dampening * vCoefficients + (1 - dampening) * vCoefficientsNew;
end
%----------------------------------------------------------------
% Compute value and policy functions over fine grid
%----------------------------------------------------------------
% Compute polynomial approximation of capital accumulation policy conditional on adjustment
vCapitalCoefficients = sum(mStatePoly' .* (ones(nState,1) * vCapitalAdjust'),2);
vCapitalCoefficients = vCapitalCoefficients ./ vStatePolySquared;
% Compute policy functions over fine grid
[vCapitalAdjust,vCapitalConstrained,vCutoff] = computePolicies(vCoefficients,vCapitalCoefficients,wage,mFineGrid,mFinePoly,aProdPrimeFinePoly);
%----------------------------------------------------------------
% Compute stationary distribution from these decision rules,
% using histogram
%----------------------------------------------------------------
% Compute discrete transition matrix
mTransition = sparse(computeDiscreteTransitionMatrix(vCapitalAdjust,vCapitalConstrained,vCutoff));
% Iterate over transition matrix
err = 100;
iterations = 0;
vHistogram = ones(nStateFine,1) ./ nStateFine;
while err > 1e-16 && iterations < 1e4
vHistogramNew = mTransition' * vHistogram;
err = max(abs(vHistogramNew - vHistogram));
iterations = iterations + 1;
vHistogram = vHistogramNew;
end
%----------------------------------------------------------------
% Compute output of the function
%----------------------------------------------------------------
% Market clearing residual
vLaborDemand = ((exp(mFineGrid(:,1)) .* (mFineGrid(:,2) .^ ttheta) * nnu) / wage) .^ (1 / (1 - nnu)) + ((vCutoff .^ 2) ./ (2 * ppsiCapital));
residual = sum(vLaborDemand .* vHistogram) - nSS; % will later calibrate cchi to ensure labor supply = nSS
% Optional output
if nargout > 1
vCoefficientsOptional = vCoefficients;
vCapitalCoefficientsOptional = vCapitalCoefficients;
vCapitalAdjustOptional = vCapitalAdjust;
vCapitalConstrainedOptional = vCapitalConstrained;
vCutoffOptional = vCutoff;
vHistogramOptional = vHistogram;
end