pencil.m

This program calculates the equilibrium value functions from the pencil-and-paper example. LaTeX/TikZ uses the results to create Figure 2 of Abbring and Campbell's ``Last-In First-Out Oligopoly Dynamics''.

Contents

Clean up

close all
clc
clear

Set parameter values

beta=1.05^(-5);
kappa=1.25;
phi=@(N) 1;
pi = @(N) 2-2*(N>2);

chat=0.1;
ccheck=2.5;
lambda=0.1;

Solve the second firm's dynamic programming problem.

%Define the mapping from vtilde to cunderbar

cunderbar = @(vtilde) min(max((-lambda*vtilde+(1-lambda)*kappa)/((1-lambda)*pi(2)/2),chat),ccheck);

%Define the mapping from vtilde to vtildeprime.

vtildeprime = @(vtilde) ((ccheck+chat)/2)*pi(2)/2 - kappa + ...
    beta*((1-lambda)*(ccheck^2*pi(2)/4-kappa*ccheck)+lambda*vtilde*ccheck - ...
    ((1-lambda)*(cunderbar(vtilde)^2*pi(2)/4-kappa*cunderbar(vtilde))+lambda*vtilde*cunderbar(vtilde)))...
    /((ccheck-chat)*(1-beta*(1-lambda)));

% Iterate beginning with vtilde=0

vtilde0=1;
vtilde1=0;

while abs(vtilde0-vtilde1)>1e-5
    vtilde0=vtilde1;
    vtilde1=vtildeprime(vtilde0);
end

% Assign the resulting thresholds and continuation values to their variables.
vtilde2=vtilde0;
cunderbar2=cunderbar(vtilde0);
coverbar2=min((-lambda*vtilde2+(1-lambda)*kappa+phi(2)*(1-beta*(1-lambda))/beta)/((1-lambda)*pi(2)/2),ccheck);

Solve the first firm's dynamic programming problem.

% Define the mapping from vtilde to cunderbar

cunderbar = @(vtilde) max(((1-lambda)*kappa-lambda*vtilde(1))/((1-lambda)*pi(1)),chat);

% Define the mapping from vtilde to vtildeprime

vtildeprime1 = @(vtilde) ((chat+ccheck)/2)*pi(1) - kappa + ...
                beta*((1-lambda)*(coverbar2^2*pi(1)/2-kappa*coverbar2)+lambda*vtilde(1)*coverbar2...
                -((1-lambda)*(cunderbar(vtilde)^2*pi(1)/2-kappa*cunderbar(vtilde))+lambda*vtilde(1)*cunderbar(vtilde)) ...
                +(1-lambda)*(ccheck^2*pi(2)/4-kappa*ccheck)+lambda*vtilde(2)*ccheck ...
                -((1-lambda)*(coverbar2^2*pi(2)/4-kappa*coverbar2)+lambda*vtilde(2)*coverbar2))...
                /((1-beta*(1-lambda))*(ccheck-chat));

vtildeprime2 = @(vtilde) ((chat+ccheck)/2)*pi(2)/2 - kappa + ...
                beta*((1-lambda)*(cunderbar2^2*pi(1)/2-kappa*cunderbar2)+lambda*vtilde(1)*cunderbar2...
                -((1-lambda)*(cunderbar(vtilde)^2*pi(1)/2-kappa*cunderbar(vtilde))+lambda*vtilde(1)*cunderbar(vtilde)) ...
                +(1-lambda)*(ccheck^2*pi(2)/4-kappa*ccheck)+lambda*vtilde(2)*ccheck ...
                -((1-lambda)*(cunderbar2^2*pi(2)/4-kappa*cunderbar2)+lambda*vtilde(2)*cunderbar2))...
                /((1-beta*(1-lambda))*(ccheck-chat));

vtildeprime = @(vtilde) [vtildeprime1(vtilde) vtildeprime2(vtilde)];

% Iterate beginning with vtilde = [vtilde2 vtilde2];

vtilde0=zeros(1,2);
vtilde1=[vtilde2 vtilde2];
while max(abs(vtilde0-vtilde1))>1e-5
    vtilde0=vtilde1;
    vtilde1=vtildeprime(vtilde0);
end

% Assign the resulting thresholds and continuation values to their variables.
clear vtilde0
cunderbar1=cunderbar(vtilde1);
coverbar1 = min((-lambda*vtilde1(1)+(1-lambda)*kappa+phi(1)*(1-beta*(1-lambda))/beta)/((1-lambda)*pi(1)),ccheck);

Calculate value function points for plotting.

%Calculate the highest point of the monopoly branch
v11coverbar2=beta*((1-lambda)*(coverbar2*pi(1)-kappa)+lambda*vtilde1(1))/(1-beta*(1-lambda));

%Calculate the lowest and highest points of the duopoly branch
v12cunderbartwo=beta*((1-lambda)*(cunderbar2*pi(2)/2-kappa)+lambda*vtilde1(2))/(1-beta*(1-lambda));
v12ccheck=beta*((1-lambda)*(ccheck*pi(2)/2-kappa)+lambda*vtilde1(2))/(1-beta*(1-lambda));

%Calculate the highest point of the second entrant's value function
v2ccheck=beta*((1-lambda)*(ccheck*pi(2)/2-kappa)+lambda*vtilde2)/(1-beta*(1-lambda));

Export the equilibrium calculations to LaTeX macros for use by TikZ for creating Figure 2.

f1=fopen('ac2aPencilConstants.tex','w');

fprintf(f1,'\\def\\pencilChat{%3.2f}\n',chat);
fprintf(f1,'\\def\\pencilCcheck{%3.2f}\n',ccheck);
fprintf(f1,'\\def\\pencilPiTwo{%3.2f}\n',pi(2));
fprintf(f1,'\\def\\pencilPiOne{%3.2f}\n',pi(1));
fprintf(f1,'\\def\\pencilPhiTwo{%3.2f}\n',phi(2));
fprintf(f1,'\\def\\pencilPhiOne{%3.2f}\n',phi(1));
fprintf(f1,'\\def\\pencilCunderbarTwo{%3.2f}\n',cunderbar2);
fprintf(f1,'\\def\\pencilCoverbarTwo{%3.2f}\n',coverbar2);
fprintf(f1,'\\def\\pencilCunderbarOne{%3.2f}\n',cunderbar1);
fprintf(f1,'\\def\\pencilCoverbarOne{%3.2f}\n',coverbar1);
fprintf(f1,'\\def\\pencilVOneOneCoverbarTwo{%3.2f}\n',v11coverbar2);
fprintf(f1,'\\def\\pencilVOneTwoCunderbarTwo{%3.2f}\n',v12cunderbartwo);
fprintf(f1,'\\def\\pencilVOneTwoCcheck{%3.2f}\n',v12ccheck);
fprintf(f1,'\\def\\pencilVTwoCcheck{%3.2f}\n',v2ccheck);

fclose(f1);

Quit Matlab

We only wish to quit if we are running this from the makefile. To detect this,import the make level. If we are running this from within make, this will be nonempty. For extra security, we don't even bother with this step if we are not running within unix or mac.

if ( isunix || ismac )

    makelevel=getenv('MAKELEVEL');

    if ~strcmp(makelevel,'')
        quit
    end

end