%% Name of file: "Incognito_code_Eq_v1.m" % This Matlab code generates the equilibrium hiding probaiblity, lambda^*, % in "Surfing Incognito: Welfare Effects of Anonymous Shopping" by Johan N. M. % Lagerlöf. The latest version of the paper, the code and other material % are available at www.johanlagerlof.com. % The following code creates data used in Fig 6a in the paper (so for relatiely high values of delta). clear all; % Clean up the memory. Leq = zeros(1,10); % This defines a vector with zeroes. The entries of the % vector will later be replaced with the lambda^* expressions that we solve for. D = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]; % A vector with nine different delta values. for d = 1:length(D) % The start of the "outside" loop. This loop runs through the different delta values in D. x0 = [0.1]; % The initial guess. for nc=1:10; % The start of the "inside" loop. This loop works through ten % different values of c (the parameter in the quadratic cost function). c=2*nc/5; % This defines the c values (from 2/5 through 20/5). options = optimset('Display','off'); % Sets some options for the command sol used below. % The command below solves for the root of the equation that defines the % equilbrum values of lambda, given a delta and a c value. f = @(x) [D(d).*(1-x) .* (2+(1-2.*x-x.^2)).*D(d) .* (8+2.*(1-7.*x-2.*x.^2).*D(d) + (1+x+5.*x.^2+x.^3) .*(D(d)).^2) ./ (4.* (4+(1-6.*x-3.*x.^2).*D(d) + x.*(1+x).^2 .*(D(d)).^2).^2) - c.*x]; sol(nc) = fsolve(f, x0,options); % end % The end of the "inside" loop. z=sol'; % Puts the roots found above in the vector z (one entry for each of the c values). Leq=[Leq;sol]; % A matrix with the found roots added to the last row. The % first row is, at this stage, a row with zeros; this will be deleted later. hold on % Makes sure that the old graphs do not get erased as we move % through the loop and pass by the plot command more times. C = [2/5 4/5 6/5 8/5 10/5 12/5 14/5 16/5 18/5 20/5]; % Defines a vector with % the c values, for the purpose of plotting against these. plot(C,z) % Plots the roots, for a given delta, against the c values. end hold off Leq = Leq([2:end],:) % Erases the first row of zeros in the Leq matrix. f1 = figure; %%%%%% The following code creates data used in Fig 6b in the paper (so for %%%%%% relatiely low values of delta). clear all; Leq = zeros(1,10); D = [0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15]; for d = 1:length(D) x0 = [0.1]; for nc=1:10; c=2*nc/5; options = optimset('Display','off'); f = @(x) [D(d).*(1-x) .* (2+(1-2.*x-x.^2)).*D(d) .* (8+2.*(1-7.*x-2.*x.^2).*D(d) + (1+x+5.*x.^2+x.^3) .*(D(d)).^2) ./ (4.* (4+(1-6.*x-3.*x.^2).*D(d) + x.*(1+x).^2 .*(D(d)).^2).^2) - c.*x]; sol(nc) = fsolve(f, x0, options); end z=sol'; Leq=[Leq;sol]; hold on C = [2/5 4/5 6/5 8/5 10/5 12/5 14/5 16/5 18/5 20/5]; plot(C,z); end hold off Leq = Leq([2:end],:)