﻿Interwoven VisualPreview: //NR3PWVEWS005/cms04/main/Dallas/DallasFed/WORKAREA/DallasFedWA/site/assets/documents/institute/wpapers/2007/0001_ImperfComp2ctry.m%-------------------------------------------------------------------------%
% OG model with two countries and perfect competition
%-------------------------------------------------------------------------%

%-------------------------------------------------------------------------%
% Opening Commands
%-------------------------------------------------------------------------%
clear ;
cd('C:\Rick\UT Economics\Paper Ideas\Dissertation\OG two country\MatLab') ;

%-------------------------------------------------------------------------%
% Functional Forms
%-------------------------------------------------------------------------%
% u(C') = (C'^(1-sigma)-1)/(1-sigma) for sigma>=0
%       = log(C')                  for sigma = 1
% g(n) = chi*(n)^xi
% C' = ((C'^h)^theta)*((C'^f)^(1-theta))
% n  = steady state labor supply
% Ch = steady state domestic consumption of domestic goods
% Cf = steady state domestic consumption of foreign goods
% V(x,x*) = max_x u(C'(x,x*)) - g(n(x,x*))
%-------------------------------------------------------------------------%

%-------------------------------------------------------------------------%
% Parameter values and exogenous values
%-------------------------------------------------------------------------%
% sigma = coefficient of constant relative risk aversion
% chi   = cost function scale parameter
% xi    = cost function shape parameter
% theta = home bias parameter
% epsilon = elasticity of substitution among differentiated goods
%-------------------------------------------------------------------------%
sigma = 3 ;
chi   = 0.5 ;
xi    = 2 ;
theta = 0.65 ;
epsilon = 10 ;

if sigma <= 0
    disp('parameter restriction error: sigma <= 0')
    break
elseif chi <= 0
    disp('parameter restriction error: chi <= 0')
    break
elseif xi < 1
    disp('parameter restriction error: xi < 1')
    break
elseif theta < 0.5
    disp('parameter restriction error: theta < 0.5')
    break
elseif theta > 1
    disp('parameter restriction error: theta > 1')
    break
elseif epsilon <= 1
    disp('parameter restriction error: epsilon <= 1')
    break
end

%-------------------------------------------------------------------------%
% State Space
%-------------------------------------------------------------------------%
% xmax  = maximum value that state space of x can be to keep steady
%         state percent of currency portfolio that is domestic currency
%         greater than zero. x must also be greater than 0.
% x     = domestic money growth rate (monetary policy)
% xstar = foreign money growth rate (monetary policy)
% xsize = number of states in the x vectors
%-------------------------------------------------------------------------%
xmax  = 1/(1-theta) - 0.01 ;
x     = [0.5:0.05:xmax]' ;
xstar = [0.5:0.05:xmax]' ;
xsize = length(x) ;

%-------------------------------------------------------------------------%
% Steady state values
%-------------------------------------------------------------------------%
% n_x_xstar       = the steady state value of domestic
%                   employment/production given domestic and foreign
%                   monetary policy (1st dimensionor columns = values of x,
%                   2nd dimension or rows = values of xstar)
% nstar_x_xstar   = the steady state value of foreign
%                   employment/production given domestic and foreign
%                   monetary policy (1st dimension or columns = values of x,
%                   2nd dimension or rows = values of xstar)
% c_h_x_xstar     = the steady state value of domestic consumption of the
%                   domestically produced good given domestic and foreign
%                   monetary policy (1st dimension or columns = values of x,
%                   2nd dimension or rows = values of xstar)
% c_f_x_xstar     = the steady state value of domestic consumption of the
%                   foreign produced good given domestic and foreign
%                   monetary policy (1st dimension or columns = values of x,
%                   2nd dimension or rows = values of xstar)
% cstar_f_x_xstar = the steady state value of foreign consumption of the
%                   foreign produced good given domestic and foreign
%                   monetary policy (1st dimension or columns = values of x,
%                   2nd dimension or rows = values of xstar)
% cstar_h_x_xstar = the steady state value of foreign consumption of the
%                   domestically produced good given domestic and foreign
%                   monetary policy (1st dimension or columns = values of x,
%                   2nd dimension or rows = values of xstar)
%-------------------------------------------------------------------------%
Delta = theta - sigma*theta - xi ;
Sigma = (1 - theta)*(1-sigma) ;
Omega = (epsilon/(epsilon-1))*((chi*xi)/((theta^(theta*(1-sigma)))*((1-theta)^((1-theta)*(1-sigma))))) ;

if sigma == 1 
    disp('I do not have the log version of ss n done yet')
    break ;
else
    n_x_xstar = (Omega^((Delta-Sigma)/(Delta^2-Sigma^2)))...
        .*((repmat(x',xsize,1)).^((Delta)/(Delta^2-Sigma^2)))...
        .*((repmat(xstar,1,xsize)).^((-Sigma)/(Delta^2-Sigma^2))) ;
    nstar_x_xstar = (Omega^((Delta-Sigma)/(Delta^2-Sigma^2)))...
        .*((repmat(xstar,1,xsize)).^((Delta)/(Delta^2-Sigma^2)))...
        .*((repmat(x',xsize,1)).^((-Sigma)/(Delta^2-Sigma^2))) ;
end

c_h_x_xstar     = theta*n_x_xstar ;
c_f_x_xstar     = (1-theta)*nstar_x_xstar ;
C_x_xstar = ((c_h_x_xstar).^theta).*((c_f_x_xstar).^(1-theta)) ;
cstar_f_x_xstar = theta*nstar_x_xstar ;
cstar_h_x_xstar = (1-theta)*n_x_xstar ;
Cstar_x_xstar = ((cstar_f_x_xstar).^theta).*((cstar_h_x_xstar).^(1-theta)) ;

if sigma == 1
    disp('I do not have the log version of ss V done yet')
    break ;
else
    V_x_xstar = (((((c_h_x_xstar).^theta).*((c_f_x_xstar).^(1-theta))).^(1-sigma) - 1)./(1-sigma))...
        - chi*(n_x_xstar).^xi ;
    Vstar_x_xstar = (((((cstar_f_x_xstar).^theta).*((cstar_h_x_xstar).^(1-theta))).^(1-sigma) - 1)./(1-sigma))...
        - chi*(nstar_x_xstar).^xi ;
end

[Vmax_xstar,xmax_xstar] = max(V_x_xstar,[],2) ;
[Vstarmax_x,xstarmax_x] = max(Vstar_x_xstar,[],1) ;

%-------------------------------------------------------------------------%
% 3-D graphics of steady state values
%-------------------------------------------------------------------------%

% figure(1)
% surf(x,xstar,n_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('employment/production')
% title('Domestic SS Employment as Function of Domestic and Foreign MP','FontSize',12)
% 
% figure(2)
% surf(x,xstar,nstar_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('employment/production')
% title('Foreign SS Employment as Function of Domestic and Foreign MP','FontSize',12)
% 
% figure(3)
% surf(x,xstar,c_h_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('c_h')
% title('Domestic SS C_h as Function of Domestic and Foreign MP','FontSize',12)
% 
% figure(4)
% surf(x,xstar,c_f_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('c_f')
% title('Domestic SS C_f as Function of Domestic and Foreign MP','FontSize',12)
% 
% figure(5)
% surf(x,xstar,cstar_h_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('c_h')
% title('Foreign SS C_h as Function of Domestic and Foreign MP','FontSize',12)
% 
% figure(6)
% surf(x,xstar,cstar_f_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('c_f')
% title('Foreign SS C_f as Function of Domestic and Foreign MP','FontSize',12)

figure(7)
surf(x,xstar,V_x_xstar)
xlabel('x, domestic MP')
ylabel('x*, foreign MP')
zlabel('V(x,x*)')
title('Domestic Lifetime U as Function of Domestic and Foreign MP','FontSize',12)

hold on
%Make line for best response function
xmaxval_xstar = ones(length(xstar),1)*x(xmax_xstar(1)) ;
%figure(10)
plot3(xmaxval_xstar,xstar,V_x_xstar(:,xmax_xstar(1))+ones(xsize,1)*0.01,'k','LineWidth',5)
xlabel('x, domestic MP')
ylabel('x*, foreign MP')
zlabel('V(x,x*)')
grid on
%title('Domestic BR function x as function of x^*','FontSize',12)
hold off

% figure(8)
% surf(x,xstar,Vstar_x_xstar)
% xlabel('domestic MP')
% ylabel('foreign MP')
% zlabel('V(x*,x)')
% title('Foreign Lifetime U as Function of Domestic and Foreign MP','FontSize',12)
% 
% figure(9)
% subplot(2,1,1)
% plot(xmax_xstar)
% subplot(2,1,2)
% plot(xstarmax_x)
0001_ImperfComp2ctry.m   


      New Form Entry New Page Import Edit Upload Submit More... Undo Changes 
       
      Select Image 
      Check Links 
       
      Review 
      View Source 
      Visual Differences 
      Source Differences 
       
      Copy 
      Move 
      Delete 
      Rename 
      Convert 
       
      Tag 
      Versions 
      Properties 
       
      Attach To Task... 
      Assign 
      Add to Favorites 
