I am using the Bayesian estimation algorithm. For six shocks, I use six observable. Smoothed series perfectly match these observable as expected. What is odd is that some other smoothed variables (not used as observable) such as asset prices ( p ) and dividends (d) appear with a negative sign in the oo folder.

On the other hand, in stochastic simulation which follows the estimation, the simulated series for p and d look quite plausible and have the right signs. I wonder whether Kalman smoothing is doing anything strange here or something I am doing wrong.

I attach the code and the dataset for your perusal.
Thanks in advance for your help.

It would be useful to post the graphs of the relevant series. Apologies, but I have not had the time to run the code yet.
A log-linear model would yield variables in terms of deviations from steady-state; so why is it a problem that variables are negative as well as positive?
For the observed series in an estimation, the smoothed variables should match perfectly with the data. The unobserved series would be a function of the parameters and the observed series. Do the smoothed asset prices ( I suppose Tobin’s q?) look implausible even when you transform them to log-level terms ( not % deviations from ss)?

asset_price_plots.pdf (167.7 KB)
Dear Reuben,
Many thanks for the response. I attach the plots of the smoothed asset price series which looks highly implausible because it is always negative.
To contrast this, I also plot the asset price series that is generated from stochastic simulation. It looks very plausible because the steady state asset price is 4.68. .
I suspect that the source of the problem is a composite parameter called deltaprime which is appearing in the model loop. This deltaprime also appears in dividend and asset price equations. MCMC smooths this composite parameter which makes the smoothed dividend and asset price negative. The other alternative is to keep the composite parameter outside the model loop. But I was told that there will be issues about parameter dependence in estimation because while key parameters will be updated during the estimation, the composite parameter will not be updated.

I have still not run the code, but did go through it.
If deltaprime is a composite parameter and not an endogenous variable, why don’t you update it for each set of potential parameter values, in the model section using the notation: #deltaprime = the expression for it ;
Then deltaprime would need to be removed from the list of endogenous variables, I think.

but in the current specification, what does the kalman smoothed deltaprime look like? I guess it would be just a constant because its components are simply parameters (which are given aunique values at the mean or mode when the smoother is on).

Thanks again for thinking about it. Deltaprime and gammstar cannot be treated as local variables because these are function of delta (depreciation rate) and varrho (risk aversion) which are following individual shock processes. Thus these are changing over time. Thus they are treated in the code as a regular endogenous variables.

I now realise that these composite parameters are not really the source of the problem. Even if I kept it outside the model block and fix them at their steady state values, the same issue still arises.

As you say the smoothed unobserved variables functions of parameters and observed series. In principle, they can take any sign and may not have any economic content. I would rather look at the unobserved endogenous variables generated by stochastic simulations which make more sense to me. They have the right signs and hover around the steady state.

I will be grateful if you get a chance to look at my code and see whether I am making any error.

Your estimation does not make sense. From what I can see, your shock standard deviation prior means are orders of magnitude too small. Your observed data is very variable, while your prior says that this is not due to shocks. Focus on getting estimation right.

Dear jpfeifer
Many thanks for this feedback. You are right that my observable are too variable compared to the prior that I gave. As a rule of thumb, I chose the prior closer to the posterior std. Results do not change much. I am interested in some financial variables such as return, dividend growth, asset price growth and price/dividend ratio from this production model. I make return, dividend growth and price growth as three observable and the remaining three are basic macroeconomic variables such as output growth, investment growth and capital share. What is nice is that even though I do not make price/dividend ratio as an observable, the smoothed price/dividend series correlates really well with actual price/dividend ratio. This means that my estimation is not out of the mark.
What I find bizarre is that when I look at smoothed individual price and dividend series only, they appear with negative signs many times and they are not consistent with the smoothed p/d ratio. In other words, smoothed p/smoothed d does not give me smoothed p/d. On the other hand, if I look at the stochastically simulated series for p and d they look quite reasonable and consistent with simulated p/d. Is there any possible bug in the Kalman smoothing algorithm? Or am I still missing something badly?

I attach the code and dataset again for your perusal.
Thank you again for your data5.xlsx (50.9 KB)
help.

I am pretty sure the Smoother is OK. It more seems like an issue of model misspecification. The trend in meu seems to also generate a trend in p and d. The in-sample mean are not that different from the theoretical steady states. You can see a similar trend in eps_f and less clearly in u and v. All your shocks are supposed to be iid, but they do not look like white noise. That explains why stoch_simul returns different results. Here, the shocks are truly iid, while in estimation the fact that the model does not properly fit the data shows up in the smoothed shocks and variables.