Programs for "Using Cyclical Regimes of Output Growth to Predict Jobless Recoveries" by Micheal J. Dueker, appearing in the March/April issue of the Federal Reserve Bank of St. Louis Review. The programs are costrec.p07 and markov15.gss. There are also 5 equations estimated in Eviews using the 'ls' command. start costrec.p07 mu = -.632495|-.305529|.810183|1.40953; mu = -0.923834 | -0.178060 | 0.841962 | 1.41106 ; mu = -0.949154 | 0.472289 | 0.881823 | 1.859770 ; mu = -0.974893 | 0.445263 | 0.886320 | 1.899288 ; mu = -1.00600 | 0.521943 | 0.775959 | 1.85195 ; mu = -1.00030 | 0.437061 | 0.902049 | 1.89945 ; P = zeros(4,4); p[4,1] = 1; p[1:2,2] = .281|.719; p[2:3,3] = .0618|.9382; p[3:4,4] = .113| .887; P = (4.28083e-36 ~ 0.274931 ~ 3.18367e-11 ~ 4.03472e-40) | (3.92083e-14 ~ 0.725064 ~ 0.0644190~ 1.30450e-16) | ( 0.274753 ~ 4.97668e-06~ 0.935581~ 0.0941374) | ( 0.725247~ 2.22045e-16~ 4.26011e-08~ 0.905863) ; P = ( 0.330744 ~ 0.165318 ~ 0.000000 ~ 0.016131) | ( 0.557807 ~ 0.587658 ~ 0.051705 ~ 0.297909 ) | ( 0.016862 ~ 0.028756 ~ 0.948295 ~ 0.034132 ) | ( 0.094587 ~ 0.218268 ~ 0.000000 ~ 0.651829); P = ( 0.285112 ~ 0.144445 ~ 0.000000 ~ 0.020727) | ( 0.578985 ~ 0.583323 ~ 0.051319 ~ 0.334096) | ( 0.019747 ~ 0.030764 ~ 0.948681 ~ 0.036136) | ( 0.116156 ~ 0.241468 ~ 0.000000 ~ 0.609041) ; P = ( 0.287297 ~ 0.161185 ~ 6.68867e-008 ~ 0.0190675)| ( 0.580489 ~ 0.592989 ~ 0.00743789 ~ 0.326942 )| ( 0.00444117 ~ 0.00656436 ~ 0.992562 ~ 0.00777589)| ( 0.127773 ~ 0.239262 ~ 2.22045e-016 ~ 0.646214); P = ( 0.267300 ~ 0.133134 ~ 9.18590e-008 ~ 0.0163723 ) | ( 0.607963 ~ 0.612537 ~ 0.0533640 ~ 0.342089 ) | ( 0.0156673 ~ 0.0249191 ~ 0.946636 ~ 0.0302375 ) | ( 0.109070 ~ 0.229411 ~ 2.22045e-016 ~ 0.611301 ) ; /* construct vector of unconditional initial prob using tp*/ mt=eye(4)-P; mt=mt[1:3,.]|ones(1,4); init_prob=(zeros(3,1)|1)/mt; init_prob = 0.086065 | 0.326181 | 0.359891 | 0.227863 ; init_prob = 0.072234 | 0.325566 | 0.379660 | 0.222540 ; init_prob = 0.0641956 | 0.260284 | 0.476308 | 0.199212 ; init_prob = 0.0717995 | 0.366098 | 0.325883 | 0.236219 ; ucond = init_prob'mu; /* For each time period for lengthrec periods, starting with the recession onset date, calc. the long-run expectation going forward of the cumulative output loss from that recession */ load datt[185,6] = f:\multist\costp07.dat; @file comes from markov switching program below@ data = datt[.,5]; startdate= 1|40|55|86|122|165; startdate = startdate+4; @ @ lengthrec = 14; cumloss = zeros(rows(datt),rows(startdate)); rec = 1; do while rec <= rows(startdate); @ which recession @ rowstart = startdate[rec]; j = 0; do while j <= lengthrec; @ which period's expectation following onset @ @ actual loss to date @ cumloss[rowstart+j,rec] = sumc(data[rowstart:rowstart+j,1])-(j+1)*ucond; @ add future expected losses @ addcumloss = 0; @ l = 1; do while l <= lengthrec -j; @ @ addcumloss = 0; @ totpers = 4000; sims = 1; Pmat = eye(4); do while sims <= totpers; Pmat = P*Pmat; addcumloss = addcumloss + mu'(Pmat*datt[rowstart+j,1:4]')-ucond; addcumloss = addcumloss/totpers; sims = sims+1; endo; @ l = l+1; endo; @ cumloss[rowstart+j,rec] = cumloss[rowstart+j,rec] + addcumloss; j = j+1; endo; rec = rec+1; endo; output file= h:\multist\costrec.o17 reset; jobles = zeros(rows(cumloss),1); j = 1; do while j <= cols(cumloss); jobles = jobles + cumloss[.,j]; j = j+1; endo; print jobles; j = 1; do while j <= cols(cumloss); print packr(miss(cumloss[.,j],0)); j = j+1; endo; aveloss = zeros(lengthrec+1,1); j = 1; do while j <= cols(cumloss); aveloss = aveloss + packr(miss(cumloss[.,j],0))/rows(startdate); j = j+1; endo; print aveloss; rec = 1; do while rec <= rows(startdate); @ which recession @ rowstart = startdate[rec]; jobles[rowstart:rowstart+lengthrec] = jobles[rowstart:rowstart+lengthrec] -aveloss; rec = rec+1; endo; print jobles; end; /* Four State Markov Switching Model using optium for Likelihood function param={u1,u2,u3,u4,c2,c3,a1,a2,a3,a4,sigma2}; u1 1 and i < 4; tp[i,j]=cdfn(c[i+1,j]-a[j])-cdfn(c[i,j]-a[j]); endif; if i == 4; tp[i,j] = 1-cdfn(c[i,j]-a[j]); endif; j=j+1; endo; i=i+1; endo; /* construct vector of unconditional initial prob using tp*/ mt=eye(4)-tp; mt=mt[1:3,.]|ones(1,4); init_prob=(zeros(3,1)|1)/mt; format 8,4; print tp; print init_prob; print param; end; paramn2 = xout; format 8,4; print param_fnl~xout; "Calculating Hessian and its inverse.....";; "THANK YOU FOR YOUR PATIENCE..............!!!"; hout=inv(hessp(&likelihood,paramn2)); @ print gradp(&like2,paramn2); @ @hout = inv(gradp(&like2,paramn2)'gradp(&like2,paramn2)); @ grdn_fnl=gradp(&TRANS,paramn2); Hsn_fnl=grdn_fnl*hout*grdn_fnl'; SD_fnl =sqrt(diag(Hsn_fnl)); @Standard errors of the estimated coefficients@ output on; "==FINAL OUTPUT========================================================"; "likelihood value is ";; -fout; "Estimated parameters are:"; trans(paramn2); "var-cov matrix is:"; Hsn_fnl; "Standard errors of parameters are:"; sd_fnl; "==============================================================="; param_fnl~sd_fnl; -fout; @ret_num = like2(param_fnl); @ /**********************likelihood function***********************/ proc likelihood(paramp); Local tp,i,j,c,a,mt,init_prob,u,sigma,param,filter_prob,yt,t,ret_num,temp, prior_prob,sm_prob,k,prjk; param= trans(paramp); @ c= -20^501|param[5]|param[6]|param[7]|20^501; @ c = zeros(5,4); c[1,.] = -20^501*ones(1,4); c[5,.]= 20^501*ones(1,4); c[2,.] = zeros(1,4); c[3:4,1] = param[10:11]; c[3:4,2] = param[10:11]; c[3:4,3] = param[12:13]; @ 12:13 @ c[3:4,4] = param[10:11]; a=param[1:4]; tp=zeros(4,4); /*stores the transition matrix*/ i=1; do while i <= 4; j=1; do while j <= 4; if i == 1; tp[i,j] = cdfn(c[i+1,j]-a[j]); endif; if i > 1 and i < 4; tp[i,j]=cdfn(c[i+1,j]-a[j])-cdfn(c[i,j]-a[j]); endif; if i == 4; tp[i,j] = 1-cdfn(c[i,j]-a[j]); endif; j=j+1; endo; i=i+1; endo; u=param[5:8]; sigma=param[9]; /* c=-20^501|0|param[5:6]|20^501; /*20^501~Inf*/ a=param[7:10]; u=param[1:4]; sigma=param[11]; tp=zeros(4,4); /*stores the transition matrix*/ i=1; do while i<=4; j=1; do while j<=4; if i == 1; tp[i,j] = cdfn(c[i+1]-a[j]); endif; if i > 1 and i < 4; tp[i,j]=cdfn(c[i+1]-a[j])-cdfn(c[i]-a[j]); endif; if i == 4; tp[i,j] = 1-cdfn(c[i]-a[j]); endif; j=j+1; endo; i=i+1; endo; */ /* construct vector of unconditional initial prob using tp*/ mt=eye(4)-tp; mt=mt[1:3,.]|ones(1,4); init_prob=(zeros(3,1)|1)/mt; filter_prob = zeros(rows(data),4); prior_prob = zeros(rows(data),4); sm_prob = zeros(rows(data),4); ?"print transition prob. matrix"; tp; ?"print unconditional state probs"; init_prob; /* calculate first filtered prob*/ t=1; yt=data[t]; filter_prob[t,.]= (init_prob.*pdfn_new(yt,u,sigma)/ (init_prob'pdfn_new(yt,u,sigma)))'; ret_num= ln(1e-300+init_prob'pdfn_new(yt,u,sigma)); t=t+1; /*recursive calculation of prior prob*/ do while t<=rows(data); prior_prob[t,.]=(tp*filter_prob[t-1,.]')'; yt=data[t]; filter_prob[t,.]= prior_prob[t,.].*(pdfn_new(yt,u,sigma))'/ (prior_prob[t,.]*pdfn_new(yt,u,sigma)); ret_num=ret_num+ln(1e-300+prior_prob[t,.]*pdfn_new(yt,u,sigma)); t=t+1; endo; @ print data~(prior_prob*u)~filter_prob; @ @ smoothed probabilities @ prjk = zeros(16,1); sm_prob[rows(data),.] = filter_prob[rows(data),.]; t= rows(data)-1; do while t >= 1; j = 1; do while j <= 4; k = 1; do while k <= 4; sm_prob[t,j]=sm_prob[t,j]+ sm_prob[t+1,k]*filter_prob[t,j]*tp[k,j]/prior_prob[t+1,k]; k = k+1; endo; j= j+1; endo; t= t-1; endo; @ print filter_prob~sm_prob; @ print filter_prob~data~dat[2:rows(dat),5]; print data~(filter_prob*u)~(sm_prob*u); print sm_prob~dat[2:rows(dat),5]; print ret_num; end; end; retp(-ret_num); endp; /**********************likelihood function***********************/ proc like2(paramp); Local tp,i,j,c,a,mt,init_prob,u,sigma,param,filter_prob,yt,t,ret_num,temp, prior_prob,sm_prob,k,prjk; param= trans(paramp); /* construct transition matrix using param*/ c=-20^501|0|param[5:6]|20^501; /*20^501~Inf*/ a=param[7:10]; u=param[1:4]; sigma=param[11]; tp=zeros(4,4); /*stores the transition matrix*/ i=1; do while i<=4; j=1; do while j<=4; if i == 1; tp[i,j] = cdfn(c[i+1]-a[j]); endif; if i > 1 and i < 4; tp[i,j]=cdfn(c[i+1]-a[j])-cdfn(c[i]-a[j]); endif; if i == 4; tp[i,j] = 1-cdfn(c[i]-a[j]); endif; j=j+1; endo; i=i+1; endo; /* construct vector of unconditional initial prob using tp*/ mt=eye(4)-tp; mt=mt[1:3,.]|ones(1,4); init_prob=(zeros(3,1)|1)/mt; filter_prob = zeros(rows(data),4); prior_prob = zeros(rows(data),4); sm_prob = zeros(rows(data),4); ret_num = zeros(rows(data),1); ?"print transition prob. matrix"; tp; ?"print unconditional state probs"; init_prob; /* calculate first filtered prob*/ t=1; yt=data[t]; filter_prob[t,.]= (init_prob.*pdfn_new(yt,u,sigma)/ (init_prob'pdfn_new(yt,u,sigma)))'; ret_num[1]=-ln(1e-300+init_prob'pdfn_new(yt,u,sigma)); t=t+1; /*recursive calculation of prior prob*/ do while t<=rows(data); prior_prob[t,.]=(tp*filter_prob[t-1,.]')'; yt=data[t]; filter_prob[t,.]= prior_prob[t,.].*(pdfn_new(yt,u,sigma))'/ (prior_prob[t,.]*pdfn_new(yt,u,sigma)); ret_num[t]= -ln(1e-300+prior_prob[t,.]*pdfn_new(yt,u,sigma)); t=t+1; endo; @ smoothed probabilities @ prjk = zeros(16,1); sm_prob[rows(data),.] = filter_prob[rows(data),.]; t= rows(data)-1; do while t >= 1; j = 1; do while j <= 4; k = 1; do while k <= 4; sm_prob[t,j]=sm_prob[t,j]+ sm_prob[t+1,k]*filter_prob[t,j]*tp[k,j]/prior_prob[t+1,k]; k = k+1; endo; j= j+1; endo; t= t-1; endo; print filter_prob~sm_prob; print data~(filter_prob*u)~(sm_prob*u); end; retp(ret_num); endp; /************************************************************/ proc pdfn_new(y,u,sigma); local ret_num,i; ret_num=zeros(rows(u),1); i=1; do while i<=rows(u); ret_num[i]=exp(-0.5*ln(2*pi*sigma)-.5*(y-u[i])^2/sigma); i=i+1; endo; retp(ret_num); endp; /* proc trans(coef0); Local coef1,u;u=.0001; coef1=coef0; /* u1