Problems about Bayesian and MCMC estimation

Hello everyone, I’m doing a topic which is related to Jaaskela and Jennings’ work in 2011. For first part, basically I’m replicating the same model and methods with different country’s data.
I need to say thanks to tophukg, a user here. He was doing the same topic and shared his work. I’ve amended his model, like some input mistakes, and estimation commands. Yet now, I meet the same problem as he did. I need to get posterior estimates and the true IR graph, but Dynare doesn’t show anything after I run my model, even error message.
So I have some questions:

  1. Does this problem result from my data file or input commands? Or my estimation commands?
  2. If not, I doubt the problem be within parameter value block or obs_variable definition block, since the other model part is the same as the Journal, only country parameters differ. Especially obs_variable part, the data is quaterly, but I’m not sure if I should amend the definition for impulse response. I have tried many other ways but still it doesn’t work out.

The article (only part 2 and 3 are related to the problem), mod file and data file are attached. Appreciate it if anybody can give me some advice.
Jaaskela 2011.rar (540 KB)

You uploaded an invalid mod-file.
1.) It does not conform to Matlab’s naming convention where files need to start with a letter
2.) You have defined parameters as model-local variables. You need to fix this.

Sorry jpfeifer, I have renamed it and uploaded a new one.
And thank you for advice about the model local variables. In Jaaskela’s work, they used quaterly data, so I just try to stay in line with them and use same quaterly data but a different country. However for the obs variables part, because of the quarterly data, I am really not sure whether I should define obs_r = 4 * r, and obs_q (exchange rate) defined as q-q(-1) or just q. The code of this part in attachment is from the previous user’s work, I prefer my own thought, but none of them works out.

At least I got error message now. The model part is the same as Jaaskela’s work, so I think the problem must be in parameter or estimation part.
dis1.zip (559 KB)

Please read Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models” sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf. The original paper uses linearly detrended data. That stationary data will directly correspond to the stationary model variables. Thus, do not define the observed variables as growth rates! The interest rate in your loglinearized model that should be the log of the gross quarterly interest rate, which is approximately the net quarterly interest rate. If your observed interest rate is annual, you need the factor 4.

Really thanks for your article, professor Pfeifer, that detrend and demean part is really helpful.

Some questions: in your article’s demean part, the demeaned interest rate in my case, should be obs_r = log(1+r/(4*100)), but you said “the interest rate in your log-linearized model should be the log of gross quarterly interest rate”. I am not sure I totally understand you words and whether I defined a right obs demeaned interest rate.

And also, when I run my mod, whatever I change obs variables or not, it always shows :
Error using dynare (line 19)
syntax error at line 68
Even I downloaded other users’ data files and ran their mod, like the Stone_Geary_moments_bayes mod from user “lilia”, the error message is almost the same:
Error using dynare (line 19)
syntax error at line 153
Is that possible that other than the codes, there is something which goes wrong with my dynare ? Because I checked the known bug file you shared, there is no such error.

Or inappropriate shocks or estimation commands result in this error?

Sorry if my questions are too beginner.
dis3.zip (559 KB)

Again, you have defined parameters as model-local variables (e.g. SIGMAa). Please try the mod-files in the dynare examples folder to see whether everything works, in particular the fs2000.mod.
Regarding the interest rate, if r is your annual net interest rate in percentages as measured in your data, the corresponding quarterly gross interests is:

So what you posted is exactly what I said.

Thanks a lot, I have fixed the parameters. And yes, I have tried the examples. For fs2000 and fs2000a, I can get estimates and figures, but I got error messages for example1 and example2 in example file.
*for example1, messagess are:

MODEL SUMMARY

Number of variables: 6
Number of stochastic shocks: 2
Number of state variables: 3
Number of jumpers: 3
Number of static variables: 1
Error using table (line 281)
Wrong number of arguments.

Error in stoch_simul (line 71)
table(my_title,headers,labels,Sigma_e_,lh,10,6);

Error in example1 (line 110)
info=stoch_simul(var_list_);

Error in dynare (line 26)
evalin(‘base’,fname) ;

Caused by:
You may have intended to create a table with one row from one or more variables that are
character strings. Consider using cell arrays of strings rather than character arrays.
Alternatively, create a cell array with one row, and convert that to a table using CELL2TABLE.

*For example2, error messages are:

Error using dynare (line 19)
DYNARE: could not open example.mod

*And also I found some examples in the forum, in which those users said they are able to get results or figures. But I can’t run the mod files they shared. for example when I ran the mod (I also attached it)from Help with declaring model local variables , again I got the same error:

Error using dynare (line 19)
syntax error at line 261

*But that poster said he was able to get estimates. So maybe it arises from the dynare version? My dynare file name is dynare_v3.
dis3.zip (563 KB)

Please make sure you use Dynare 4.4.3. When running a mod-file, Dynare tells you which version it is using, e.g.

[quote]Starting Dynare (version 2016-07-16).
Starting preprocessing of the model file …[/quote]

Also, are you using Matlab or Octave?

Thank you very much professor! Now I am using Matlab, and I checked some results but I didn’t find the version information. I’m still quite sure it is not latest version though.
However, when I was trying to download the version 4.4.3, I found the school lab pc is blocked so I can’t install it.
When we got in touch with dynare, our tutor just gave us a dynare file. I don’t know whether it works if I copy a 4.4.3 file to pc directly.

If so, can anybody here share the 4.4.3 dynare file? Really appreciate any help !
Or if anybody gets different error messages when running my code (mod and data in dis3.zip), please tell me, so I can make it clear if it is a version problem or code problem. Thanks !
dis3.zip (559 KB)

You can install Dynare 4.4.3 on a different computer and the just copy the folder to a different computer.

With your current mod-file the problem is that PHIa is not defined. It should most probably either be a model-local variable or a parameter.

Thanks a lot, professor. Now I can run the mode, but I meet some new error messages.
The aim is to get the reaction and the posterior estimates of the model from a monetary shock. To equal the equations and endogenous variables’ number, I have to set the first 8 equations as model local variables.
And then it shows that there are some problems in initival value part. I have tried many different values but still it doesn’t work.
Also I slightly changed the shocks part and shock distribution part, I don’t know whether the change is right.
So is there any incorrect expressions within these parts which could lead the errors?
dis4.zip (557 KB)

First make sure your model runs with stoch_simul, before moving to estimation. The reason your model does not run is that two of your observation equations are not mean 0. You need to add

obs_r = 1+r/(4*100); obs_rs = 1+rs/(4*100);
to the initval block (and ideally make it a steady_state_model-block, because you know the steady state of your model). Then check whether the model works. After that, work on getting the observation equation right. The original paper uses demeaned growth rates, but your data is still trending. x shows a big seasonal pattern that needs to be removed. The two observation equations above are also incorrect, because the data are net rates. Your r in the model would most probably be

Thanks, I have made some changes based on your advice. The excel data has been adjusted, q, pis, xs, pi, x are log(q), log(pis), log(xs), log(pi), log(x), and r, rs are log(1+r/(4100)) and r=log(1+rs/(4100)) now.
I tried add the 2 observation equations to initval block too but it seems not work. So I tried keeping this part unchanged because now the these 2 are mean 0 (I am not sure), then I got some results from the model.
But still, something goes wrong, I can only get some weird prior values, not for all parameters. Also during estimation, there were 3 options, when I chose option 1 and 2, posterior estimation still doesn’t work.
I tried different parameter values for estimation as well, but none works out.
dis4 (2).zip (570 KB)

  1. Your data still does not match the observation equations. The data is not mean 0, while your model variables are.
  2. I guess you mean posterior estimates? That is caused by 1)
  3. Whether you select all endogenous variables or only all observed variables does not matter for estimation, just for the display of results.

Really thanks for your help and patience, professor, but I think I still don’t get the point.
As the guide says, to get data detrended and demeaned, observation equations for pi, pis, x, xs, q should be log(pi), log(pis)…log(q), and for r and rs, obs_r and obs_rs should be log(1+r/(4100) and log(1+rs/(4100)).

Also another way, when I see some people here do some preliminary data work, I tried to fix the data manually, because the data is not mean 0.
I have tried many different ways for matching observation equations and data, they still don’t match. So it’s little bit confusing that whatever I tried, the data is still not mean 0.

The variables in your model are log deviations from trend and therefore mean 0:

But the data transformation

is just the log level, not the level minus its mean. Therefore, you need

to make the data correspond to deviations from mean.

Really appreciate your help and explanation! I think I understand the guide contents now, and the data has been fixed as the guide says.
Yet the strange thing is, the error messages are still as same as previous one. I also tried different parameter values but it doesn’t make any difference. The data already has mean 0, so is there anything else in which I make mistakes? Or this part is still wrongly defined?
Thanks a lot!
dis444.zip (585 KB)

But some of your data still has trends. You fixed the interest rate, but the same problem exists for inflation. Moreover, x trends and has a clear seasonal pattern. What happened to the linear detrending advocated by the original article?

I think the original paper didn’t focus too much on the estimation part. In part 3.1, they just explained that, for large economy they use linearly-detrended log US real GDP (xs), demeaned CPI and demeaned interest rate. For small open economy, they used linearly-detrended log real GDP (x), demeaned trimmed-mean inflation, demeaned cash rate, and linearly-detrended log of exchange rate.
And the posterior statistics are based on 1 million draws using MCMC with 20% burn-in period. I think this part doesn’t influence on the estimation.
These are all their words about the estimation part, quite short.

Thanks for pointing out my problems again. And as I understand, like the guide shows, the data could be detrended by:
obs_pi=pi_hat=log(pi_data)-log(mean(pi_data))
obs_y=y_hat=log(y)-log(y_bar)=log(y)-log(mean(y))
So I fixed the data, to match the observation equations. I’m not sure whether I misunderstand something.

Also for x, it trends and has seasonal pattern, does it mean that xs and x need to be fixed like interest rate?

Please read my Guide carefully. There is an important difference between trending variables (like x) and stationary, but not mean 0 variables (pi and r). Those need to be treated differently. The original paper is quite explicit here.
To take out the linear trend, use something like