| 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]; | |