//Take home exam for Econ 232B, Time Series, taught by Roger Farmer and invi var c, k, L, U, V, a, t, d, B, z, dlogY, dlogC, dlogI, Hours; varexo eB, ed, eT, eA;//, err; parameters alfa, chi, om, gama, beta, deltaK, deltaL, teta, a0, t0, rhod, rhoB, sigmaA, sigmaT, sigmad, sigmaB, L0, be, fi, eta, B0, c0, k0, U0, V0, z0, sigmae; alfa = 0.34; // share of capital in the production technology chi = 1.204; // preference proportionality parameter for labor gama = 0.00; // preference power parameter for labor beta = 0.99; // discount factor deltaK = 0.0314; // depreciation rate of capital deltaL = 0.1; // separation rate for labor teta = 0.4; // share of effort in the matching technology a0 = 1.0028; // speed on neutral technological growth t0 = 1.0013; // speed of investment-specific technological growth rhod = 0.50; // persistence of the shock to preferences rhoB = 0.50; // persistence of the shock to the matching technology sigmaA = 0.01; // variance of the shock to neutral technology sigmaT = 0.01; // variance of the shock to investment-specific technology sigmad = 0.01; // variance of the shock to preferences sigmaB = 0.01; // variance of the shock to matching technology sigmae = 0.0010; L0 = 0.66; // labor hours in steady-state be = 0.83; // preference proportionality parameter for searching for a job //compute steady-state om = be/(teta^teta*(1-teta)^(1-teta)); z0 = (a0*t0^alfa)^(1/(1-alfa)); fi = ((z0/beta - (1-deltaK)/t0)/(alfa*a0))^(-1/(1-alfa)); eta = a0*fi^alfa - fi*(z0-(1-deltaK)/t0); B0 = om*(1-beta*(1-deltaL))/((1-alfa)*a0*(fi^alfa)/(eta*L0) - chi*L0^gama); c0 = eta*L0; k0 = fi*L0; U0 = deltaL*(L0/B0)*(teta/(1-teta))^(1-teta); V0 = (1-teta)*U0/teta; model; //equations for the steady-state #om = be/(teta^teta*(1-teta)^(1-teta)); #z0 = (a0*t0^alfa)^(1/(1-alfa)); #fi = ((z0/beta - (1-deltaK)/t0)/(alfa*a0))^(-1/(1-alfa)); #eta = a0*fi^alfa - fi*(z0-(1-deltaK)/t0); #B0 = om*(1-beta*(1-deltaL))/((1-alfa)*a0*(fi^alfa)/(eta*L0) - chi*L0^gama); #c0 = eta*L0; #k0 = fi*L0; #U0 = deltaL*(L0/B0)*(teta/(1-teta))^(1-teta); #V0 = (1-teta)*U0/teta; // forward-looking rule for labor (exp(d)/c)*(1-alfa)*a*(k(-1)/L)^alfa - chi*L^gama = om*(1/B - beta*(1-deltaL)/B(+1)); //(1) //consumption 1 = beta*exp(d(+1)-d)*(c/c(+1))*(1/z)*((1-deltaK)/t(+1) + alfa*a(+1)*(L(+1)/k)^(1-alfa)); //(2) // resource constraint for capital k*z = (1-deltaK)*(k(-1)/t) + a*(k(-1)^alfa)*(L^(1-alfa)) - c; //(3) // evolution of labor L = L(-1)*(1-deltaL) + B*(U^teta)*(V^(1-teta)); //(4) // efficient allocation of vacancies and search effort teta*V = (1-teta)*U; //(5) //exogenous process for neutral technology a = a0*exp(sigmaA*eA); //(6) //exogenous process for investment-specific technology t = t0*exp(sigmaT*eT); //(7) //exogenous process for preferences d = rhod*d(-1) + sigmad*ed; //(8) //exogenous process for matching technology B = B0^(1-rhoB)*B(-1)^rhoB*exp(sigmaB*eB); //(9) //growth factor z^(1-alfa) = a*t^alfa; //(10) //measurement equation for hours Hours = L;//*exp(sigmae*err); //(11) //measurement equation for real output growth exp(dlogY) = a*(L/L(-1))^(1-alfa)*((k(-1)/k(-2))*z(-1)*t(-1))^alfa; //(12) //measurement equation for consumption growth exp(dlogC) = z(-1)*(c/c(-1)); //(13) //measurement equation for investment growth exp(dlogI) = z(-1)*t(-1)/(k(-1)*z(-1)*t(-1) - (1-deltaK)*k(-2))*(k*z*t - (1-deltaK)*k(-1)); //(14) end; // initial values are set at steady-state initval; c=c0; k=k0; L=L0; U=U0; V=V0; a=a0; t=t0; d=0; B=B0; z=z0; dlogY=log(a0*(z0*t0)^alfa); dlogC=log(z0); dlogI=log(z0*t0); Hours=L0; eA=0; eB=0; eT=0; ed=0; //err=0; end; //find steady-state (it coincides) steady; //check conditions for uniqueness and existence of equilibrium check; //set shock variances if 0 //simulate - 1, estimate - 0 shocks; var eA = 1; var eB = 1; var eT = 1; var ed = 1; //var err= 0; end; // simulate a stochastic 2-nd order path length 100 periods stoch_simul(order=1 , irf=20, periods=175); // save simulation results to file datatomfile('TakeHomeSimul',[]); //here estimation part starts else shocks; var eA = 1; var eB = 1; var eT = 1; var ed = 1; var eA,ed = 0; var eB,ed = 0; var eT,ed = 0; var eT,eB = 0; //var err= 0; end; //priors for estimated parameters estimated_params; //alfa, beta_pdf, 0.340, 0.05; // share of capital in the production technology chi, gamma_pdf, 1.204, 0.25; // preference proportionality parameter for labor gama, normal_pdf, 0.000, 2.00; // preference power parameter for labor //beta, beta_pdf, 0.990, 0.002; // discount factor //deltaK,gamma_pdf,0.0314, 0.005; // depreciation rate of capital //deltaL,gamma_pdf, 0.10, 0.03; // separation rate for labor //teta, beta_pdf, 0.40, 0.15; // share of effort in the matching technology - not identified a0, gamma_pdf, 1.0028, 0.001, 1.00001, 0; // speed on neutral technological growth //t0, gamma_pdf, 1.0013, 0.0005, 1.00001, 0; // speed of investment-specific technological growth rhod, beta_pdf, 0.50, 0.20; // persistence of the shock to preferences rhoB, beta_pdf, 0.50, 0.20; // persistence of the shock to the matching technology sigmaA, inv_gamma_pdf, 0.01, 0.005; // variance of the shock to neutral technology sigmaT, inv_gamma_pdf, 0.025, 0.010; // variance of the shock to investment-specific technology sigmad, inv_gamma_pdf, 0.020, 0.010; // variance of the shock to preferences sigmaB, inv_gamma_pdf, 0.05, 0.03; // variance of the shock to matching technology //L0 , normal_pdf, 0.66, 0.05; // labor hours in steady-state //be = 0.83; // preference proportionality parameter for searching for a job //sigmae, inv_gamma_pdf, 0.0015, 0.0005; // variance of the shock to preferences //corr eB, eT, normal_pdf, 0, 0.4; //corr eT, ed, normal_pdf, 0, 0.1; //corr eA, ed, normal_pdf, 0, 0.1; //corr eB, ed, normal_pdf, 0, 0.1; end; varobs dlogY, dlogC, dlogI, Hours; global lgx_TeX_ lgy_TeX_ ; lgx_TeX_ = 'e_{A,t}'; lgx_TeX_ = strvcat(lgx_TeX_,'e_{B,t}'); lgx_TeX_ = strvcat(lgx_TeX_,'e_{d,t}'); lgx_TeX_ = strvcat(lgx_TeX_,'e_{T,t}'); lgy_TeX_ = 'a_{t}'; lgy_TeX_ = strvcat(lgy_TeX_,'B_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'c_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'d_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'dlogC_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'dlogI_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'dlogY_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'Hours_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'k_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'L_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'t_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'U_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'V_{t}'); lgy_TeX_ = strvcat(lgy_TeX_,'z_{t}'); estim_params_.tex = '\chi'; estim_params_.tex = strvcat(estim_params_.tex,'\gamma'); estim_params_.tex = strvcat(estim_params_.tex,'a'); estim_params_.tex = strvcat(estim_params_.tex,'\rho_{d}'); estim_params_.tex = strvcat(estim_params_.tex,'\rho_{B}'); estim_params_.tex = strvcat(estim_params_.tex,'\sigma_{A}'); estim_params_.tex = strvcat(estim_params_.tex,'\sigma_{T}'); estim_params_.tex = strvcat(estim_params_.tex,'\sigma_{d}'); estim_params_.tex = strvcat(estim_params_.tex,'\sigma_{B}'); options_.varobs_TeX = 'dlogY'; options_.varobs_TeX = strvcat(options_.varobs_TeX,'dlogC'); options_.varobs_TeX = strvcat(options_.varobs_TeX,'dlogI'); options_.varobs_TeX = strvcat(options_.varobs_TeX,'Hours'); //estimation(datafile=TakeHomeSimul,mh_replic=2000,mh_nblocks=1,mh_jscale=0.3); estimation(datafile=rbcdata,mode_file=Takehome_mode,mode_compute=0,mh_replic=5000,mh_nblocks=5,mh_jscale=0.5,tex); //estimation(datafile=rbcdata,mh_replic=1000,mh_nblocks=1,mh_jscale=0.4,tex); end; rbcdata; T=size(time,1); A1=ones(T+1,1); B1=ones(T+1,1)*dr_.ys(2); T1=ones(T+1,1); D1=ones(T+1,1); for i=2:T+1 A1(i,1)=A1(i-1,1)*(oo_.SmoothedVariables.a(i-1)+dr_.ys(1)); B1(i,1)=oo_.SmoothedVariables.B(i-1)+dr_.ys(2); T1(i,1)=T1(i-1,1)*(oo_.SmoothedVariables.t(i-1)+dr_.ys(11)); D1(i,1)=exp(oo_.SmoothedVariables.d(i-1)); end; B10=B1(2); A10=A1(2); D10=D1(2); T10=T1(2); B1=B1/B10; A1=A1/A10; D1=D1/D10; T1=T1/T10; figure; plot(time,A1(2:T+1),time,T1(2:T+1),time,B1(2:T+1),time,D1(2:T+1),... 'LineWidth',2) legend('Neutral','Investment-specific','Matching','Preferences') F=[dr_.ghx,dr_.ghu]; C=dr_.ys; C=C(dr_.order_var'); T1=0; T=size(oo_.SmoothedShocks.eA,1); time=zeros(T,1); time(T)=2007+1/8+3/4; for i=(T-1):(-1):1 time(i)=time(i+1)-1/4; end; eA=oo_.SmoothedShocks.eA(1:T)'; eB=oo_.SmoothedShocks.eB(1:T)'; ed=oo_.SmoothedShocks.ed(1:T)'; eT=oo_.SmoothedShocks.eT(1:T)'; //% exercise 1: all shocks X= [zeros(8,T+T1);eA;eB;ed;eT]; Y= zeros(14,T+T1); Y(1:14,1)=C; for i=2:T Y(1:14,i)=F*X(:,i-1); X(1:7,i)=Y(7:13,i); X(8,i)=X(1,i-1); Y(1:14,i)=C+Y(1:14,i); end for i=1:T GDP(i)=exp(sum(Y(3,1:i))); CONS(i)=exp(sum(Y(1,1:i))); INV(i)=exp(sum(Y(2,1:i))); HOURS(i)=Y(4,i); end //% exercise 1: no A shock X= [zeros(8,T+T1);mean(eA)*ones(size(eA));eB;ed;eT]; Y= zeros(14,T+T1); Y(1:14,1)=C; for i=2:T Y(1:14,i)=F*X(:,i-1); X(1:7,i)=Y(7:13,i); X(8,i)=X(1,i-1); Y(1:14,i)=C+Y(1:14,i); end for i=1:T GDPA(i)=exp(sum(Y(3,1:i))); CONSA(i)=exp(sum(Y(1,1:i))); INVA(i)=exp(sum(Y(2,1:i))); HOURSA(i)=Y(4,i); end //% exercise 1: no B shock X= [zeros(8,T+T1);eA;mean(eB)*ones(size(eB));ed;eT]; Y= zeros(14,T+T1); Y(1:14,1)=C; for i=2:T Y(1:14,i)=F*X(:,i-1); X(1:7,i)=Y(7:13,i); X(8,i)=X(1,i-1); Y(1:14,i)=C+Y(1:14,i); end for i=1:T GDPB(i)=exp(sum(Y(3,1:i))); CONSB(i)=exp(sum(Y(1,1:i))); INVB(i)=exp(sum(Y(2,1:i))); HOURSB(i)=Y(4,i); end //% exercise 1: no d shock X= [zeros(8,T+T1);eA;eB;mean(ed)*ones(size(ed));eT]; Y= zeros(14,T+T1); Y(1:14,1)=C; for i=2:T Y(1:14,i)=F*X(:,i-1); X(1:7,i)=Y(7:13,i); X(8,i)=X(1,i-1); Y(1:14,i)=C+Y(1:14,i); end for i=1:T GDPd(i)=exp(sum(Y(3,1:i))); CONSd(i)=exp(sum(Y(1,1:i))); INVd(i)=exp(sum(Y(2,1:i))); HOURSd(i)=Y(4,i); end //% exercise 1: no B shock X= [zeros(8,T+T1);eA;eB;ed;mean(eA)*ones(size(eT))]; Y= zeros(14,T+T1); Y(1:14,1)=C; for i=2:T Y(1:14,i)=F*X(:,i-1); X(1:7,i)=Y(7:13,i); X(8,i)=X(1,i-1); Y(1:14,i)=C+Y(1:14,i); end for i=1:T GDPT(i)=exp(sum(Y(3,1:i))); CONST(i)=exp(sum(Y(1,1:i))); INVT(i)=exp(sum(Y(2,1:i))); HOURST(i)=Y(4,i); end figure; for i=1:4 subplot(2,2,i) if i==1 plot(time(1:T), GDP(1:T),time(1:T), GDPA(1:T)) title('GDP') legend('All shocks','No TFP shock') elseif i==2 plot(time(1:T), CONS(1:T),time(1:T), CONSA(1:T)) title('Consumption') legend('All shocks','No TFP shock') elseif i==3 plot(time(1:T), INV(1:T),time(1:T), INVA(1:T)) title('Investment') legend('All shocks','No TFP shock') else plot(time(1:T), HOURS(1:T),time(1:T), HOURSA(1:T)) title('HOURS') legend('All shocks','No TFP shock') end end figure; for i=1:4 subplot(2,2,i) if i==1 plot(time(1:T), GDP(1:T),time(1:T), GDPB(1:T)) title('GDP') legend('All shocks','No Matching shock') elseif i==2 plot(time(1:T), CONS(1:T),time(1:T), CONSB(1:T)) title('Consumption') legend('All shocks','No Matching shock') elseif i==3 plot(time(1:T), INV(1:T),time(1:T), INVB(1:T)) title('Investment') legend('All shocks','No Matching shock') else plot(time(1:T), HOURS(1:T),time(1:T), HOURSB(1:T)) title('HOURS') legend('All shocks','No Matching shock') end end figure; for i=1:4 subplot(2,2,i) if i==1 plot(time(1:T), GDP(1:T),time(1:T), GDPd(1:T)) title('GDP') legend('All shocks','No Preference shock') elseif i==2 plot(time(1:T), CONS(1:T),time(1:T), CONSd(1:T)) title('Consumption') legend('All shocks','No Preference shock') elseif i==3 plot(time(1:T), INV(1:T),time(1:T), INVd(1:T)) title('Investment') legend('All shocks','No Preference shock') else plot(time(1:T), HOURS(1:T),time(1:T), HOURSd(1:T)) title('HOURS') legend('All shocks','No Preference shock') end end figure; for i=1:4 subplot(2,2,i) if i==1 plot(time(1:T), GDP(1:T),time(1:T), GDPT(1:T)) title('GDP') legend('All shocks','No Investment shock') elseif i==2 plot(time(1:T), CONS(1:T),time(1:T), CONST(1:T)) title('Consumption') legend('All shocks','No Investment shock') elseif i==3 plot(time(1:T), INV(1:T),time(1:T), INVT(1:T)) title('Investment') legend('All shocks','No Investment shock') else plot(time(1:T), HOURS(1:T),time(1:T), HOURST(1:T)) title('HOURS') legend('All shocks','No Investment shock') end end