Dynare's automatic detrending engine

I was trying to understand how Dynare’s automatic detrending engine works, so I tried to write 2 versions of a simple RBC model with stochastic growth: one where I detrended everything myself; and one using Dynare’s detrending engine.
I believe that the model and steady-state equations are correct because I get the same numerical values from the steady command.
But when I run an estimation with the same datafile, I get different results for the posteriors.
Could someone shed some light on why the two versions aren’t equivalent?

I’m uploading both codes and the datafile.
RBC_Growth_Detrended.zip (4.0 KB)

Thanks in advance.

Maybe this will help clarify what my production function and growth process looks like:
y_t = A_t k_{t-1}^{\alpha} (z_t h_{t})^{1-\alpha}
z_t^z = \frac{z_t}{z_{t-1}}
\log(z_t^z) = (1-\rho_z) \log(\overline{z^z}) + \rho_z \log(z_{t-1}^z) + \epsilon_{z,t}
So in steady-state my economy is still growing at rate \overline{z^z}.

Could it be that there is a timing error in the detrending of your Euler equation? Shouldn’t it be zz(+1) there?

You are absolutely right. I had done it right in paper, but then missed the (+1) when writing the mod file. Now the results are pretty close to each other. Thank you very much.
If you don’t mind I have one more question: if I would like to use the observable in logs, but without first-differencing (so it is NOT stationary), is there a way that could be done with the detrending engine?

I am not sure I am following. What exactly are you trying to do? The detrending engine takes care of the trends in the model variables, i.e. transforms them into stationary variables. But what you seem to be asking is about treating the data so that it matches the model variables. Here, the detrending engine will not help.

After running the estimation I would like to graph some results, but in levels, not in growth rates.
The way I´m doing this now is that I just reestablish the levels outside of Dynare, after running the estimation, by using the initial levels that I had taken off when treating the data.
But then I saw there is an “observation_trends” block and thought that by using this I might be able to keep my observables in levels and this command would take care of detrending them. But I couldn’t get this to work and your “Guide to Specifying Observation Equations” (which is very good, by the way, as has helped me a lot) does not reference this command.

The observation_trends-block only works with (log-)linear trends. Often, when we use growth rates, we are agnostic about whether the trend is deterministic or stochastic. Dynare can therefore not automatically handle this. For which objects do you want to compute the levels? Smoothed variables?

Yes, for the Smoothed variables.

Why would you need that? For the observables, there is no uncertainty about the smoothed values. They are identical to the observed variables. Or are you thinking about estimating the trend growth which is relevant for other variables in the model?

Yes, I am estimating the trend growth.
My idea is to construct a sort of “potential output” series by applying the trend growth over an initial level of potential output.
For now I´m assuming an initial output gap as the difference between the smoothed mean of y in the first period and the steady-state of y (taken from oo_.Smoother.SteadyState). I then add this output gap to my observable y in the first period to have a potential output in the same levels as my observable y.

That sounds reasonable. You may want to have a look at the files at https://github.com/DynareTeam/dynare/tree/master/tests/observation_trends_and_prefiltering
They may be useful