Skip to content

Fix predetermined_variables command with model-local variables

The mod-file

@#define predet=1

var K q;

@#if predet
    predetermined_variables K;
@#endif

parameters
a b delta r alpha dt
K_inf q_inf;

a=1;
b=1;
delta = 0.023;
alpha = 0.33;
r = 0.01;
dt=1;
q_inf = 1+(1+a)*b*delta^a;
K_inf = (((r+delta)*q_inf-a*b*delta^(a+1))/alpha)^(1/(alpha-1));

@#if predet==0
// Model block without predetermined_variables statement
    model;
    # I = K(-1)*((q-1)/((1+a)*b))^(1/a);
    # w = alpha*K(-1)^(alpha-1)+a*b*(I/K(-1))^(a+1);
    K = K(-1) + (I-delta*K(-1))*dt;
    q(+1) = q + (r+delta)*q*dt - w*dt;
    end;

@#else
// Model block with predetermined_variables statement
    model;
    # I = K*((q-1)/((1+a)*b))^(1/a);
    # w = alpha*K^(alpha-1)+a*b*(I/K)^(a+1);
    K(+1) = K + (I-delta*K)*dt;
    q(+1) = q + (r+delta)*q*dt - w*dt;
    end;
@#endif

steady_state_model;
K = K_inf;
q = q_inf;
end;

initval;
K = 20;
q = q_inf;
end;

endval;
K = K_inf;
q = q_inf1;
end;

check;

simul(periods=100, tolx=1e-12, tolf=1e-12, no_homotopy);
    # I = K*((q-1)/((1+a)*b))^(1/a);
    # w = alpha*K^(alpha-1)+a*b*(I/K)^(a+1);
    K(+1) = K + (I-delta*K)*dt;

rplot K;
rplot q;

yields wrong results. The relevant parts of the dynamic file corresponding to

    # I = K*((q-1)/((1+a)*b))^(1/a);
    K(+1) = K + (I-delta*K)*dt;

are

I__ = y(2)*((y(3)-1)/((1+params(1))*params(2)))^(1/params(1));
lhs =y(2);
rhs =y(1)+params(6)*(I__-params(3)*y(1));

Here, y(1) stores K and y(2) stores K(+1). As can be seen, in the created model-local variable, the capital stock is not shifted backwards, despite the predetermined_variables statement.

Upon fixing this, we should turn the file into a unit test.