I am trying to find the competitive equilibrium in OLG using the following code:
function F = OLG_closed_tax2(x)
%global variables
global delta beta a0 b0 alpha Z T tauk taul
% Constants
V = 8;
% Preallocate F
F = zeros(V*T,1);
% Decision variables
C_young = x(1:V:TV); % Consumption for young
L_young = x(2:V:TV); % Leisure for young
C_old = x(3:V:TV); % Consumption for old
K = x(4:V:TV); % Capital
Aprime = x(5:V:TV); % Asset or savings
tauk = x(6:V:TV); %tax on capital
taul = x(7:V:TV); %tax on labour
G = x(8:V:TV); %Government Spending
% L_t and r are recalculated, not directly taken from x
L_t = 1 - L_young; % Labour for young, directly calculated
% Adjustments and calculations
A = [a0; Aprime]; % Adjustments to include initial asset and shift for correct dimension
% Utility functions and wages/returns calculations
uc_y = 1 ./ C_young; % Marginal utility of consumption by young
ul_y = 1 ./ L_young; % Marginal utility of leisure by young
uc_o = 1 ./ C_old; % Marginal utility of consumption by old
r = (alpha .* K.^(alpha-1) .* L_t.^(1-alpha)).Z^(1-alpha) - delta; % Rate of return
w = (1-alpha) . K.^alpha .* L_t.^(-alpha).*Z^(1-alpha); % Wages
% System of equations
F(1:V:VT) = (1-taul(1:T)) . w .* L_t - Aprime - C_young; % Budget constraint for young
F(2:V:VT) = A(1:T) . (1 + (r(1:T).(1-tauk(1:T)))) - C_old(1:T); % Budget constraint for old
F(3:V:VT) = uc_y .* (w .(1-taul(1:T))) - ul_y; % Labor-leisure condition
F(4:V:V(T-1))= beta .* (1 + ((r(2:T)-delta).(1-tauk(2:T)))) . uc_o(2:T) - uc_y(1:T-1);% Euler equation for consumption smoothing
F(5:V:VT) = A(1:T) - K(1:T); % Asset market clearing
F(V(T-1)+4) = A(T+1) - A(T); % No Ponzi condition
F(6:V:VT) = w . L_t .* taul + r .* tauk .* K - G;
end
Everything is fine, except I am getting a bit deviation towards the end. What could be the issue?