File size: 8,695 Bytes
b4ae6c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
function Z=solvemodel(x, targs, vers, show)

% % This function solves the model, given (1) values for the parameters that
% don't change, which are global variables, (2) values for "calibrated"
% parameters, over which the fsolve function is searching, and which are
% passed to this function as the vector 'x'. 
% 
% The second argument, 'targs,' gives values for the three statistics whose
% values are being targeted by fsolve as part of the calibration exercise. 
% The vector of values, 'Z,' that are returned by this function are the 
% squared residuals that fsolve seeks to set to zero.
%
% The variable 'vers,' determines which variables are being passed to the
% function in 'x' and which ones are fixed at the global values set in the
% main m-file (as specified below).
%
% For the variable 'show,' a value of 1 tells the function to print the
% values of the various statistics of interest.
%
% 

% parameters:
global pigrdpts pigrid pigriddiv yb yg beta b gam eta pkh lam alph pi0 kh sigeps A kr

% output or results that we want to be available globally:
global pe pf u e0 e1 w0 w1 tendist probmatch probg H_pi_dist pibar theta oneqhazrate twoqhazrate threeplushazrate hiresrate jfr meanvacdur 

if vers==1
    localpi0=pi0;
    localkh=kh;
    localsigeps=x(1);
    localA=x(2);
    localkr=x(3);
elseif vers==2
    localpi0=x(1);
    localkh=kh;
    localsigeps=sigeps;
    localA=x(2);
    localkr=x(3);
elseif vers==3
    localpi0=pi0;
    localkh=x(3);
    localsigeps=x(1);
    localA=x(2);
    localkr=kr;
end


% % Compute the cumulative distribution of pi, conditional on normally
% distributed signal (z). This must be re-computed every time the values
% of sigeps or pi0 change (which is every time that this function is
% called).

% Find value of z such that pi equals a particular value of pigriddiv
for j=1:pigrdpts+1
    zz(j)=fsolve(@(z) pigriddiv(j)-localpi0*exp(-(z-yg)^2/2/localsigeps^2)/(localpi0*exp(-(z-yg)^2/2/localsigeps^2)+(1-localpi0)*exp(-(z-yb)^2/2/localsigeps^2)), 0, optimoptions('fsolve','TolFun',1e-16,'Display','off')); 
end    

% Probabilities of getting a value of pi between two successive values of
% pigriddiv (the range surrounding a value of pigrid)
H_pi_dist(1,:)=localpi0*normcdf(zz(2:end), yg, localsigeps)+(1-localpi0)*normcdf(zz(2:end), yb, localsigeps)-(localpi0*normcdf(zz(1:end-1), yg, localsigeps)+(1-localpi0)*normcdf(zz(1:end-1), yb, localsigeps));
H_pi_dist(1,:)=H_pi_dist(1,:)/sum(H_pi_dist(1,:)); % normalize, to ensure elements sum to 1 exactly.


%% Solve Bellman equations

xx=1/2000; % adjustment factor for convergence of pe
pe=.2;     % initial value for pe

% Create/initiate value functions
S0old=zeros(1,length(pigrid));
S1old=zeros(1,length(pigrid));
Je0old=zeros(1,length(pigrid));
Je1old=zeros(1,length(pigrid));
Juold=0;
Ve0old=zeros(1,length(pigrid));
Ve1old=zeros(1,length(pigrid));
Vuold=0;
Vu=0;

difpe=1;
tol=1e-8;
while abs(difpe)>tol

    pf=localA^(1/(1-gam))*pe^((-gam)/(1-gam));

    difs=1;
    while difs>tol
        S0new=max(pigrid*(yg-yb)+yb-localkh-b+beta*(1-lam)*(alph*pigrid*(pkh*S1old(end)+(1-pkh)*S0old(end))+(1-alph)*(pkh*S1old+(1-pkh)*S0old))-...
            beta*pe*eta*H_pi_dist*S0old',0);

        S1new=max(pigrid*(yg-yb)+yb-b+beta*(1-lam)*(alph*pigrid*S1old(end)+(1-alph)*S1old)-...

            beta*pe*eta*H_pi_dist*S0old',0);
        difs=max(max(abs(S1old-S1new)),max(abs(S0old-S0new)));
        S1old=S1new;
        S0old=S0new;
    end       

    peold=pe;
    Ju=(-localkr+beta*pf*(1-eta)*H_pi_dist*S0new')/(1-beta);

    difpe=Ju;

    pe=peold*(1+difpe*xx);  % increase worker's finding rate if Ju>0

end

theta=pe/pf;
w0=b+eta*(pigrid*yg+(1-pigrid)*yb-localkh-b+localkr*theta);
w1=b+eta*(pigrid*yg+(1-pigrid)*yb-b+localkr*theta);

pibar=pigrid(sum(S0new==0));

%% Calculate statistics of interest, given the equilibrium pe, pf, and pibar from above

probmatch=H_pi_dist*(pigrid>pibar)';         % fraction of meetings with high enought pi to form/continue match



probg=(H_pi_dist/sum(H_pi_dist(pigrid>pibar)))*(pigrid.*(pigrid>pibar))'; % probability that matches are actually good (conditional on having been formed)

trans=zeros(3,3);                            % three states: unemployed, unknown type, known good matches

trans=[1-pe*probmatch lam+(1-lam)*alph*(1-probg) lam;...
        pe*probmatch (1-lam)*(1-alph) 0;...
        0 (1-lam)*alph*probg 1-lam];

% steady state
mtr=eye(3)-trans;
mtr(3,1:3)=1;
invmtr=inv(mtr);
erg=invmtr(:,3);
u=erg(1);                   % unemployment
e0=erg(2);                  % matches of unknown type
e1=erg(3);                  % matches known to be good


% % Calculate the job tenure distribution
% --Allow mass of one unit to enter and the trace the realized tenure 
% distribution of that cohort 
% --This is equivalent to looking at the point-in-time distribution if one 
% unit is allowed to enter each period. The whole distribution would simply
% scale up or down with the size of the mass of entrants.

tendist=[0;1;0]; 
trans1=trans;
trans1(:,1)=0;              % don't allow any exits from unemployment after first period, so this just tracks the initial mass of entrants
for i=2:2000                % 2000 periods is 2000/52 (roughly 40) years
    tendist(:,i)=trans1*tendist(:,i-1) ; 
end

% fqseps: All separations among jobs newly created in the quarter=(start in first week of quarter and separate within 12
% periods)+(start in second week of quarter and separate within 11
% periods)+(start in third week of quarter and separate within 10)+...etc

fqseps=13*sum(tendist(2:3,1))-sum(tendist(2:3,14))-sum(tendist(2:3,13))-...
    sum(tendist(2:3,12))-sum(tendist(2:3,11))-sum(tendist(2:3,10))-...
    sum(tendist(2:3,9))-sum(tendist(2:3,8))-sum(tendist(2:3,7))-...
    sum(tendist(2:3,6))-sum(tendist(2:3,5))-sum(tendist(2:3,4))-...
    sum(tendist(2:3,3))-sum(tendist(2:3,2));

% empspells: (Employment among all tenure categories at start of
% quarter)+(new starts in 2nd week)+(new starts in third week)+...+(new
% starts in 13th week)

empspells=sum(sum(tendist(2:3,:)))+12*sum(tendist(2:3,1)); 

sqrate=fqseps/empspells;  % incidence rate of one-quarter spells (q_1 in paper)

hires=13*sum(tendist(2:3,1));

% % First quarter hazard rate: among those who enter a job in a given
% quarter, what fraction have separated by the start of the next quarter?
oneqhazrate=fqseps/hires;

% Note: we could have used either tendist or scaledtendist in the above
% calculations for sqrate and fqhazrate. Whether they are scaled or not 
% doesn't matter much so long as the numerators and denominators are scaled
% equivalently.

% 2 quarter hazard rate

twoqseps=sum(sum(tendist(2:3,2:14)))-sum(sum(tendist(2:3,15:27)));
twoqhazrate=twoqseps/sum(sum(tendist(2:3,2:14)));

% 3+ quarters separation rate

threeplusseps=sum(sum(tendist(2:3,15:end)))-sum(sum(tendist(2:3,28:end)));
threeplushazrate=threeplusseps/sum(sum(tendist(2:3,15:end)));

% Quarterly hires rate (# hires in quarter divided by total employment spells)
hiresrate=hires/empspells;

% Monthly job-finding rate
jfr=pe*probmatch+(1-pe*probmatch)*pe*probmatch +(1-pe*probmatch)^2*pe*probmatch+(1-pe*probmatch)^3*pe*probmatch; % weekly frequency: "month"==4 weeks

% % Mean vacancy duration in days
% meanvacdur=7*(1/pf/probmatch);

% Mean vacancy duration in weeks
meanvacdur=(1/pf/probmatch);

% print output 

if show==1
%     fid=fopen('results.txt','w');
%     fprintf(fid,'Unemployment rate: \t\t\t\t %g\r', u);
%     fprintf(fid,'Monthly job-finding rate:\t\t %g\r', jfr);
%     fprintf(fid,'Ave. vacancy duration (weeks):\t %g\r', 1/pf/probmatch);
%     fprintf(fid,'Prob(good|match):\t\t\t\t %g\r', probg);
%     fprintf(fid,'1-H(pi^n):\t\t\t\t\t\t %g\r', probmatch);
%     fprintf(fid,'Worker meeting rate:\t\t\t\t %g\r', pe);
%     fprintf(fid,'First quarter hazard rate:\t\t %g\r',oneqhazrate);
%     fprintf(fid,'Second quarter hazard rate:\t\t %g\r',twoqhazrate);
%     fprintf(fid,'3+ quarter hazard rate:\t\t\t %g\r',threeplushazrate);
%     fprintf(fid,'Hires rate:\t\t\t\t\t\t %g\r',hiresrate);
%     fclose(fid);
%     type results.txt

% print results to be cut-and-pasted into tables in Latex
    fid=fopen('results2.txt','w');
    fprintf(fid,'& %.3f & %.3f & %.3f & %.3f & %.3f & %.2f & %.3f', oneqhazrate, twoqhazrate, threeplushazrate, hiresrate, jfr, meanvacdur, u);
    fclose(fid);
    type results2.txt

    
end

Z=[(log(targs(1))-log(probg))^2; (log(targs(2))-log(jfr))^2; (log(targs(3))-log(meanvacdur))^2];