% Parameters parameters H beta2 beta1 sigma1 sigma2 sigmah eta m phi nu ABad AGood; H = 1; beta1 = 0.98; beta2 = 0.99; sigma1 = 1; sigma2 = 1; sigmah = 1; eta = 1; m = 0.89; phi = 0.057143; nu = 0.041224; PrintFreq = 100; SaveFreq = 100; % States var_state X; XPts = 701; XMin=0.0; XMax=1; X=linspace(XMin,XMax,XPts); % Shocks shock_num=3; var_shock A; ABad = 0.97; AGood = 1.03; A = [ABad 1 AGood]; % From Equation (17) shock_trans = [ 0.7204 1-0.7204 0.0 (1-0.872)/2 0.872 (1-0.872)/2 0.0 1-0.7204 0.7204 ]; % Tensor variables var_tensor; % Variable for the last period var_policy_init h L; inbound_init h 1e-20 H; inbound_init L 1e-20 2; var_aux_init c cp q; model_init; Y = A*h^nu * L^(1-nu); q = nu*A*h^(nu-1)*L^(1-nu); w = (1-nu)*A*h^nu*L^(-nu); c = q*H*X; cp = Y-q*H*X; hp = H-h; foc_hp = -1 + phi*hp^(-sigmah)/(q*cp^(-sigma2)); foc_L = -1 + w*cp^(-sigma2)/(L^(eta-1)); equations; foc_hp; foc_L; end; end; % Endogenous variables, bounds, and initial values var_policy p q c h a cp L mu Xp[3]; inbound p 0 2 adaptive(1.5); inbound q 0 2 adaptive(1.5); inbound c 0.0 2 adaptive(1.5); inbound h 1e-20 1; inbound a 1e-20 2 adaptive(1.5); inbound L 1e-20 2 adaptive(1.5); inbound mu 0.0 1; inbound cp 0.0 2 adaptive(1.5); inbound Xp 0.0 1.2; var_aux Y YTilde b bp hp; var_interp cFuture cpFuture qFuture; cFuture = c; cpFuture = cp; qFuture = q; % Initialize using model_init initial cFuture c; initial cpFuture cp; initial qFuture q; % var_output Xp Y YTilde p q; model(X>0); Y = A*h^nu * L^(1-nu); % eq9 w = (1-nu)*A * h^nu * L^(-nu); profit = (Y-w*L)/h; [cNext',cpNext',qp'] = GDSGE_INTERP_VEC'(Xp'); Eqp = GDSGE_EXPECT{qp'}; % Transform of variable b = a - m*Eqp*h; % Implied by market clear bp = -b; hp = H-h; % Implied by budget constraint budget1 = c-(q*X*H + Y-w*L - q*h - p*b); budget2 = cp-(q*(1-X)*H + w*L - q*hp - p*bp); YTilde = Y + phi*hp^(-sigmah)/(cp^(-sigma2)) * hp; % Equations in text eq10 = -1 + mu*m*Eqp*p/(q-profit) + beta1*GDSGE_EXPECT{qp'*cNext'^(-sigma1)} / ((q-profit)*c^(-sigma1)); eq11 = mu*a; eq12 = -1 + mu + beta1 * GDSGE_EXPECT{ cNext'^(-sigma1) } / (p*c^(-sigma1)); eq13 = -1 + phi*hp^(-sigmah) / (q*cp^(-sigma2)) + beta2*GDSGE_EXPECT{ qp'*cpNext'^(-sigma2) } / (q*cp^(-sigma2)); eq14 = -1 + beta2 * GDSGE_EXPECT{ cpNext'^(-sigma2) } / (p*cp^(-sigma2)); eq15 = -1 + L^(eta-1) / (w*cp^(-sigma2)); % Consistency consis1 = (qp(1)*h+b) / (qp(1)*H) / Xp(1) - 1; consis2 = (qp(2)*h+b) / (qp(2)*H) / Xp(2) - 1; consis3 = (qp(3)*h+b) / (qp(3)*H) / Xp(3) - 1; equations; % budget budget1; budget2; % Optimality condition eq10; eq11; eq12; eq13; eq14; eq15; % Consistency if A==AGood Xp(1); else consis1; end consis2; if A==ABad Xp(3); else consis3; end end; end; model(X==0); Y = A*h^nu * L^(1-nu); w = (1-nu)*A * h^nu * L^(-nu); profit = (Y-w*L)/h; [cNext',cpNext',qp'] = GDSGE_INTERP_VEC'(Xp'); Eqp = GDSGE_EXPECT{qp'}; % Transform of variable b = a - m*Eqp*h; % Implied by market clear bp = -b; hp = H-h; % Implied by budget constraint budget2 = cp-(q*(1-X)*H + w*L - q*hp - p*bp); YTilde = Y + phi*hp^(-sigmah)/(cp^(-sigma2)) * hp; % Equations in Guangyu's new note eq7 = -1 + phi*hp^(-sigmah) / (q*cp^(-sigma2)) + beta2 * GDSGE_EXPECT{ qp'*cpNext'^(-sigma2) } / (q*cp^(-sigma2)); eq8 = -1 + beta2 * GDSGE_EXPECT{ cpNext'^(-sigma2) } / (p*cp^(-sigma2)); eq9 = -1 + L^(eta-1) / (w*cp^(-sigma2)); eq11 = -1 + (q - profit)/(m*Eqp*p); % Consistency consis1 = (qp(1)*h+b) / (qp(1)*H) / Xp(1) - 1; consis2 = (qp(2)*h+b) / (qp(2)*H) / Xp(2) - 1; consis3 = (qp(3)*h+b) / (qp(3)*H) / Xp(3) - 1; equations; % budget constraint eq11; % This is equivalent to enterpreneur's budget when c and X = 0 budget2; % Optimality condition c-0; mu-0; % I have set mu=0, though mu is not known ex-ante. a-0; eq7; eq8; eq9; % Consistency if A==AGood Xp(1); else consis1; end consis2; if A==ABad Xp(3); else consis3; end end; end; simulate; num_periods = 10000; num_samples = 100; initial X 0.5 initial shock 1; var_simu Y YTilde; X' = Xp'; end;