Simple RBC model setup error for bayesian estimation

I have a very simple basic RBC model and i am trying to set it up in dynare. Below is how i have set it up. i, however, get the error - line 39, col 1: syntax error, unexpected INT_NUMBER

``````@#define use_real_data=0

var c k z c_obs;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 2. Exogenous variables.

varexo eps;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 3. Parameters.

parameters beta alpha delta rho sigma_z;
beta = 0.98;
alpha  = 0.400;
delta = 1.000;
rho = 0.420;
sigma_z = 1.000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 5. Model block

model;
1/c = beta*((1/c(+1))*(1+alpha*(z(+1)*(k(+1)^(alpha-1))- delta)));
z*(k^alpha) + k*(1-delta) = c + k(+1);
z(+1) = (rho*z) + sigma_z*eps;
c_obs = log(c);
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

//6. Initial Values

initval;
1/beta = (1+(alpha*(z*(k^alpha))/k)- delta);
z*(k^alpha) = c+(k*delta);
z=1
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 7. Shocks

shocks;

var eps=0.0068^2;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

//check the starting values for the steady state
resid;

// compute steady state given the starting values
// check Blanchard-Kahn-conditions
check;

//simulate data for estimation
@# if use_real_data==1
stoch_simul(order=1,periods=0) c;
@# else
stoch_simul(order=1,periods=200) c;
datatomfile('data_simulated_bm',[]);
@# endif
``````

Can someone please help in explaining why the syntax error is arising? I will be really grateful.

I solved the above issue and program runs fine now but I had following follow-up questions: am new to dynare and I am using another language for bayesian estimation. I see that my results from dynare do not match my set of codes. I therefore have two following questions:

1)Does Dynare not use Chris Sims gensys as a default program to solve the model? Since I use gensys that might be the reason for discrepancy?

1. Also, I use a standard Kalman Filter - multivariate Kalman Filter algorithm, which is commonly used for state estimation in linear dynamic systems with Gaussian noise. In order to generate the initial state mean, I sample from a multivariate normal distribution with mean. This variable is initialized as a NumPy array of zeros with a length equal to the number of endogenous variables. Initial state covariance matrix is initialized as an identity matrix with dimensions : (no. of endogenous variable```x```no. of endogenous variables).

Does Dynare default code use above (1) and (2). I am anticipating that because (!) and (2) are not being used, I get different estimation results.

1. Is there a way I can change some settings in syntax of Estimation command so that (1) and (2) above are used so that I can match my estimation results with dynare? Otherwise, my results will not be comparable.

I am following the example of “RBC_baseline_first_diff_bayesian.mod” for reference in Dynare.

I already went through dynare reference manual and various questions posted on the dynare form but I am still not clear about (1), (2) and (3) above.

Look forward to someone’s help please.

Is the following set up correct for simple real business cycle model. Also, I am still looking for an answer for the above question posted:

``````@#define use_real_data=0

var c k z;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 2. Exogenous variables.

varexo eps;

predetermined_variables k;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 3. Parameters.

parameters beta alpha delta rho sigma_z;
beta = 0.985;
alpha  =1/3;
delta = alpha/10;
rho = 0.420;
sigma_z = 1.000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
predetermined_variables k;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 5. Model block

model;
1/c = beta/c(+1)*(alpha*(z(+1)*(k(+1)^(alpha-1)))+ 1- delta);
z*(k^alpha) + k*(1-delta) = c + k(+1);
z(+1) = (rho*z)) - rho + 1 + sigma_z*eps;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//6. Initval
initval;
z=1;
k = ((z*beta*alpha)/(1+(beta*delta)-beta))^(1-alpha);
c= z*(k^alpha) - (k*delta);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 7. Shocks

shocks;

var eps; stderr 1;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

//check the starting values for the steady state
resid;

// compute steady state given the starting values

// check Blanchard-Kahn-conditions
check;
//simulate data for estimation
@# if use_real_data==1
stoch_simul(order=1,periods=0) c;
@# else
stoch_simul(order=1,periods=200) c;
datatomfile('data_simulated_bm',[]);
@# endif
``````

Also, when I give steady state block, it does not run saying steady state did not run. Why?

1. RBC.mod (1.8 KB) should be correct.
2. Your `initval` block equation for `k` is incorrect (most likely wrong bracketing), which explains why it does not run as a `steady_state_model`-block.#
3. Dynare does not use `gensys`. But generally the particular solution technique for the quadratic matrix equation does not matter. All approaches should return results that are numerically very similar except for pathological cases. Most likely there is another issue. Before moving to estimation, you should compare simulation results, i.e. IRFs.
4. Dynare uses a different initialization by default, namely the unconditional mean (i.e. the steady state) and the unconditional variance (the solution of the Lyapunov equation).

Thank you for clarifying Prof. Pfeifer. Appreciate your help. I will check simulation and IRFs first.

I tried to run steady state model but it still throws error that steady state cannot be computed.

Only “initival” route works and I am not able to figure out why

Again, because your computation for `k` was wrong:
RBC.mod (1.8 KB)

Thank you Prof. Pfeifer appreciate your help.

I have log-linearized the simple model I am using by hand (pen and paper solution) as below:

``````equation1 = ((-ct+cs)/cs) + ((ct1-cs)/cs) - ((alpha-1)*((kt-ks)/ks)) - ((zt-zs)/zs)
equation 2 = ((zt-zs)/zs) + ((alpha+1)*((kt-ks)/ks)) - ((-ct+cs)/cs) - ((kt1-ks)/ks
equation 3 = zt - (rho*ztl) - (sigma_z*eps)
``````

where cs, zs and ks are steady state values respectively for c,k and z.

Does this look fine.

Sorry, I don’t have time to check users’ linearizations. But particularly the second equation looks incorrect. In additive equations, there will be pre-factors as the steady states will not cancel.

Also, why are you doing this? See

Sure, I understand Prof. Pfeifer. I corrected my equations. Also, I am trying the estimation in python and there I have put in place a system where I put in both - simply model equations and also the log-linearized equations to check solutions from both. So, I need log-linearization for my python codes, not dynare.

Basically, the whole purpose of getting to dynare is checking my computations from python with dynare results. Even though the algorithms might be different, the answers should match and currently, my answers do not match for both. Log-likelihood value varies and the posterior mean estimations are not very close which they should be.

Also, is there a way I can just see Kalman Filter codes that dynare uses. I guess to see the likelihood value, I compared the value"initial value of log-likelihood" before csminwel starts optimization. I am comparing that to my log-likelihood which I obtain from Python estimation to this initial value of log-likelihood. Since they differe given same initial parameter values I wanted to check dynare’s Kalman Filter with that what I use, to cross-check.

This first check always is whether the IRFs to shocks at the initial parameter values is the same across programs. The second step is then to simulate the model variables and check the mean and standard deviation of the implied observables. Particularly the mean needs to be consistent with the one in actual data.

Thank you Prof. Pfeifer. I have checked irf - at the initial parameter values it is the same across programs. The moments of the simulated data are not same across python and dynare.

But what is different? The mean?

Both the mean and the standard deviation are different.

Can I just access the Kalman Filter codes (Matlab or C) which dynare uses - a comparison might be good?
I had earlier compared the output from gensys (I know dynare does not use gensys) from MATLAB and python and they match exactly.

But how different? Significantly? That would indicate a problem with the observation equations.

It depends on the setup. Usually, matlab/kalman/likelihood/missing_observations_kalman_filter.m · master · Dynare / dynare · GitLab would be the relevant file.

So, my observable is just k in so both in python and dynare i define just k as observable. For python it is defined as kt/kss, while it is just varobs k with my simple RBC set-up which you corrected previously.

Thank you for sharing the kalman filter codes. I really appreciate your help. I really want to get to the bottom of the reason which creates a difference in the results.

And also, I am just using simulated data as of now and when I use the real data - I areday log and de-trend it.