Problem with adding a government sector in bkk.mod

Hello, I am trying to simply extend the Backus,Kehoe and Kydland (1992) model which is given as one of the example files when Dynare is installed. I have just added a government sector but the code will not run. Can anyone help?

@#define countries = “H”, “F” ]
@#define J = 4

@#for co in countries
var C_@{co} CP_@{co} L_@{co} N_@{co} A_@{co} K_@{co} Z_@{co} X_@{co} LAMBDA_@{co} S_@{co} NX_@{co} Y_@{co} G_@{co};

varexo E_@{co} U_@{co};

parameters beta_@{co} alpha_@{co} eta_@{co} mu_@{co} gamma_@{co} theta_@{co} nu_@{co} sigma_@{co} delta_@{co} phi_@{co} psi_@{co} omega_@{co} rho_@{co}@{co} tau@{co}_@{co};
@#endfor

// Lagrange multiplier of aggregate constraint
var LGM;

parameters rho_@{countries[1]}@{countries[2]} rho@{countries[2]}@{countries[1]};
parameters tau
@{countries[1]}@{countries[2]} tau@{countries[2]}_@{countries[1]};

model;
@#for co in countries

Y_@{co} = ((LAMBDA_@{co}*K_@{co}(-@{J})^theta_@{co}*N_@{co}^(1-theta_@{co}))^(-nu_@{co}) + sigma_@{co}*Z_@{co}(-1)^(-nu_@{co}))^(-1/nu_@{co});
K_@{co} = (1-delta_@{co})*K_@{co}(-1) + S_@{co};
X_@{co} =
@# for lag in (-J+1):0
+ phi_@{co}*S_@{co}(@{lag})
@# endfor
;

A_@{co} = (1-eta_@{co})*A_@{co}(-1) + N_@{co};
L_@{co} = 1 - alpha_@{co}*N_@{co} - (1-alpha_@{co})*eta_@{co}*A_@{co}(-1);
C_@{co} = CP_@{co} + omega_@{co}*G_@{co};

// Utility multiplied by gamma

U_@{co} = (CP_@{co} + omega_@{co}*G_@{co}^mu_@{co}*L_@{co}^(1-mu_@{co}))^gamma_@{co};

// FOC with respect to consumption
psi_@{co}*mu_@{co}/C_@{co}*U_@{co} = LGM;

// FOC with respect to labor
// NOTE: this condition is only valid for alpha = 1
psi_@{co}(1-mu_@{co})/L_@{co}U_@{co}(-alpha_@{co}) = - LGM * (1-theta_@{co})/N_@{co}(LAMBDA_@{co}*K_@{co}(-@{J})^theta_@{co}*N_@{co}^(1-theta_@{co}))^(-nu_@{co})*Y_@{co}^(1+nu_@{co});

// FOC with respect to capital
@# for lag in 0:(J-1)
+beta_@{co}^@{lag}*LGM(+@{lag})*phi_@{co}
@# endfor
@# for lag in 1:J
-beta_@{co}^@{lag}*LGM(+@{lag})phi_@{co}(1-delta_@{co})
@# endfor
= beta_@{co}^@{J}*LGM(+@{J})theta_@{co}/K_@{co}(LAMBDA_@{co}(+@{J})*K_@{co}^theta_@{co}*N_@{co}(+@{J})^(1-theta_@{co}))^(-nu_@{co})*Y_@{co}(+@{J})^(1+nu_@{co});

// FOC with respect to stock of inventories
LGM=beta_@{co}LGM(+1)(1+sigma_@{co}*Z_@{co}^(-nu_@{co}-1)*Y_@{co}(+1)^(1+nu_@{co}));

// Shock process
@# if co == countries[1]
@# define alt_co = countries[2]
@# else
@# define alt_co = countries[1]
@# endif
(LAMBDA_@{co}-1) = rho_@{co}@{co}*(LAMBDA@{co}(-1)-1) + rho_@{co}@{alt_co}*(LAMBDA@{alt_co}(-1)-1) + E_@{co};

// Shock process
@# if co == countries[1]
@# define alt_co = countries[2]
@# else
@# define alt_co = countries[1]
@# endif
(G_@{co}-1) = tau_@{co}@{co}*(G@{co}(-1)-1) + tau_@{co}@{alt_co}*(G@{alt_co}(-1)-1) + U_@{co};

NX_@{co} = (Y_@{co} - (C_@{co} + X_@{co} + G_@{co} + Z_@{co} - Z_@{co}(-1)))/Y_@{co};
@#endfor

// World ressource constraint
@#for co in countries
+C_@{co} + X_@{co} +G_@{co} + Z_@{co} - Z_@{co}(-1)
@#endfor
=
@#for co in countries
+Y_@{co}
@#endfor
;

end;

@#for co in countries
beta_@{co} = 0.99;
mu_@{co} = 0.34;
gamma_@{co} = -1.0;
alpha_@{co} = 1;
eta_@{co} = 0.5; // Irrelevant when alpha=1
theta_@{co} = 0.36;
nu_@{co} = 3;
sigma_@{co} = 0.01;
delta_@{co} = 0.025;
phi_@{co} = 1/@{J};
psi_@{co} = 0.5;
omega_@{co} = 1;
@#endfor

rho_H_H = 0.906;
rho_F_F = 0.906;
rho_H_F = 0.088;
rho_F_H = 0.088;

tau_H_H = 0.31;
tau_F_F = -0.19;
tau_H_F = -0.43;
tau_F_H = 0.44;

initval;
@#for co in countries
LAMBDA_@{co} = 1;
NX_@{co} = 0;
Z_@{co} = 1;
A_@{co} = 1;
L_@{co} = 0.5;
N_@{co} = 0.5;
Y_@{co} = 1;
K_@{co} = 1;
C_@{co} = 1;
CP_@{co} = 1;
S_@{co} = 1;
X_@{co} = 1;
G_@{co} = 1;

E_@{co} = 0;
U_@{co} = 0;
@#endfor

LGM = 1;
end;

shocks;
var E_H; stderr 0.00852;
var E_F; stderr 0.00852;
corr E_H, E_F = 0.258;

var U_H; stderr 0.00352;
var U_F; stderr 0.00352;
corr U_H, U_F = 0.158;

end;

steady;
check;

stoch_simul(order=1, hp_filter=1600, nograph);

The first error that you get is the following:

ERROR: bkkalt.mod:36.1-55: U_H has wrong type, you cannot use it within as left-hand side of a pound ('#') expression

The problem is therefore located on line 36. It has to do with the “U” variables, that you declare as exogenous, but that you also use in a pound-sign expression, which is forbidden. I guess you want to remove the declaration of U as an exogenous. You also need to remove it from the initialization blocks. Alternatively you can declare U as an endogenous, if you want to get results for that variable.