Based on your dynare code of “Real business cycle in emerging countries”, I change a little of the domestic interest rate function. Then I match the new code with another country’s data. Using dynare 2015-08-16 edition,I think the estimation results look fine, except the following issues after mode finding:
Warning: Matrix is singular to working precision.
In lyapunov_symm (line 151)
In dsge_likelihood (line 379)
In mode_check (line 143)
In dynare_estimation_1 (line 365)
In dynare_estimation (line 92)
In au (line 303)
In dynare (line 223)
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND
= NaN.
In kalman_filter (line 182)
In dsge_likelihood (line 651)
In mode_check (line 143)
In dynare_estimation_1 (line 365)
In dynare_estimation (line 92)
In au (line 303)
In dynare (line 223)
Could help give me some advise to solve this problem?
Please find attached data and code files if you need.
I will try my best to explain it and hope will not make you feel confused due to my poor English.What I change to your original code is mainly the interest rate equation(financial friction model) and debt.
The orignal paper define interest rate in model : rt=rstar+psi*(exp(Dt+1/Xt-dbar)-1)+exp(mu-1)-1 , and Dt+1/Xt should be equal to dt+1,however the authers make Dt+1/Xt=dt in stead of dt+1 in their appendix. I guess this might be a typo,since Uribe and Schmitt-Grohe write a textbook “Open economy macroeconomics” which has not been published yet and in this text book Chapter 5, they correct the interest rate equation to make Dt+1/Xt=dt+1.
I do not know why they calibrate d=0.007. According to the original AER paper, it writes “We set the parameter dbar to induce a small steady-state trade balance to output ratio of about 0.25%, as observed on average in Argentina over the period 1900-2005” . I think the value of dbar is calculated from budget constraint at steady state.Howeve,budget constrain has tbbar and dbar at steady state, if both sides divided by ybar, we can get dbar/ybar is a function of tbbar/ybar,which might match the data TB/Y, here "bar"mean steady state value). So I put ybar in the interest rate equation .
At same time , I suppose tbbar/ybar(steady state of detrended TB/ steady state of detrended Y) equal to average TB/Y data value. Is this right? Otherwise we won’t know the value of tbbar/ybar. In their textbook chapter 5 section 4 ,they use rt=rstar+psi*(exp((Dt+1/Xt-dbar)/ybar)-1) . And it seems that they also calibrate tbbar/ybar=average TB/Y data value.Since in my own data,trade blance to output raito on average is negative, then dbar/ybar (denote it to be d_share)would be negative, so I calibrate it to be d_share=-0.66(calculated from budget constraint)
So I write my code like the following(related to dbar part):
(1). My Interest Rate
r = RSTAR + psi*(exp((log(d(+1))/ybar)-(dbar/ybar)) - 1)+exp(mu-1)-1;
compared to yours
r = RSTAR + psi*(exp(d-dbar) - 1)+exp(mu-1)-1;
(2).My Trade balance
log(tb)= log(d) - log(d(+1))*g/r;
Compared to yours
log(tb)= d - d(+1)*g/r;
(3).My steady_state_model
dbar=ybar*d_share;
d=dbar;
c =(gbar/r-1)*d +y-s-invest;
d=exp(d);
Compared to yours
d = dbar;
c =(gbar/r-1)*d +y-s-invest;
Do you think there is some problem if I change the code like the above?
You can adjust your model however you deem sensible. I can only tell you that for your first point, the replication code at the AER clearly shows they used the timing with d_t:
[quote=“jpfeifer”]You can adjust your model however you deem sensible. I can only tell you that for your first point, the replication code at the AER clearly shows they used the timing with d_t:
I find in your code it writes resource constraint asy= log(tb) + c + s + invest + phi/2 * (k(+1)/k*g -gbar)^2;
however, according to the original paper appendix, it should be y= log(tb) + c + s + invest + phi/2 * (k(+1)/k*g -gbar)^2*k;.
Is it a typo of your code?
Please find attached appendix to Real business cycle in emerging countries.
Dear Huan, the answer is yes and no. My code currently follows the replication codes at the AER one to one. And there, the trade balance is defined as
tb = yy - c - s - ivv - PHI/2 * (kp/k*g -G)^2;
But you are correct in that there is a k missing in that equation. However, this is inconsequential as this term is 0 up to first order.
I will add a disclaimer to my code.
[quote=“jpfeifer”]Dear Huan, the answer is yes and no. My code currently follows the replication codes at the AER one to one. And there, the trade balance is defined as
tb = yy - c - s - ivv - PHI/2 * (kp/k*g -G)^2;
But you are correct in that there is a k missing in that equation. However, this is inconsequential as this term is 0 up to first order.
I will add a disclaimer to my code.[/quote]
Many thanks, Johannes. Your disclaimers in code are all very helpful.
[quote=“jpfeifer”]Dear Huan, the answer is yes and no. My code currently follows the replication codes at the AER one to one. And there, the trade balance is defined as
tb = yy - c - s - ivv - PHI/2 * (kp/k*g -G)^2;
But you are correct in that there is a k missing in that equation. However, this is inconsequential as this term is 0 up to first order.
I will add a disclaimer to my code.[/quote]
Dear Johhanes,
Could I ask two more questions about trade-balance in your code?
Actually, the definition of trade-balance BEFORE detrending is
TBt=Dt-Dt+1*/rt=(dtXt-1 - dt+1Xt)/rt (here rt is gross rate)
However, the TB data Generally does NOT appear Trend, so how can the equation above be altered to
tb=d-d(+1)*g/r Do you mean TBt/Xt-1=tbt ?
Since TB in data has negative numbers, to make the steady state all positive (because of loglinear command), you define
tb=exp(tb);
tb_y=exp(tb_y);
I am just wondering how to write the original measurement equation of the observable TBt/Yt(Since I am loglinearing the whole model using pencil and paper instead of loglinear command to do it again).
By the way, the definition trade-balance to output ratio
log(tb_y)=log(tb)/y;
After the “loglinear” command, does it becomelog(log(tb_y)=log(log(tb))-logy
which is ACTUALLY(here tb_y and tb have no exp any more) log(tb_y)=logtb-logy ?
Sorry to open the discussion. I am estimating a similar model with an additional shock.
The author wrote in page 10 “Measurement errors are permitted to absorb no more than 6 percent of the variance of the corresponding observable time series”.
My question is how to implement this restriction in Dynare?
My estimation result shows that the contribution to variance decomposition of measurement error associated with trade-balance-to-output ratio is pretty high (37%). What could be the potential sources of such high contribution and how can I address this? Please note that when I set the parameter representing the debt sensitivity of interest rate (psi) to a low value of 0.001, the contribution is trivial. However, either calibrating psi with a relatively high value (0.0355) or estimating it makes the contributions of measurement error and preference shocks to variance decomposition very high.
I could not figure it out. Is there any intuition behind the connection between this parameter and preference shock?
From the dataset for Argentina, I computed the 25% of standard deviations of observables as follows:
g_y = 0.013; g_x = 0.051; g_c = 0.019; tb_y = 0.013;
In your code, you set the upper bound of the measurement errors for observables as below:
g_y sqrt(0.13);
g_c sqrt(0.19);
g_x sqrt(0.51);
tb_y sqrt(0.13);
I am certain that there is a good reason for doing this. Could you please give me a brief explanation? Does this way of setting upper bound ensure that the measurement errors will contribute upto a certain percentage?
You can do this by setting an upper bound, e.g. for the uniform distribution. Of course, you first need to compute the cutoff value based on the data’s variance.
Have a look at
Have a look at the Notes in the file:
The standard deviations of the estimated measurement error reported in Table 3 of the paper are actually variances. This mod-file reflects this difference to the published version by taking the square root.
Here’s how I compute the cutoff value:
The standard deviation of tby is 0.0154 and it’s 25% is 0.0038 and I set this value as upper bound. Is it the correct way of computing cutoff value? The Garcia-Cicco et al. also set 25% of the standard deviations of the observables as the upper bound. I use the following syntax:
Is the syntax correct for setting upper bound?
After running with this setup, I encountered the following error: Initial value(s) of SE_eps_tby_ME are outside parameter bounds.
What I understood from the Dynare manual is that if initial value is not set then the prior mean (0.00195) will be set as default. So, why is the error message? Is this because of the standard deviation (sqrt(0.0038-0.0001)^2/12)?
Probably, my problem is not measurement error hitting upper bound. It’s about the contribution of measurement error (eps_tby_ME) in posterior (mean) variance decomposition. Please have a look.
Posterior mean variance decomposition (in percent)
This high contribution (36.37%) results from setting debt-elastic interest rate parameter (psi) to 0.0355, which, in turn, is to induce theoretical standard deviation of trade-balance-to-output ratio to its empirical value (0.0154). But for a lower value (0.001) of psi, the contribution is pretty low (less than 5%).
Previously, I saw this note and had confusion. That’s why I raised this issue.
Yes, that is correct. You must be setting the initial value somewhere else to get that message.
Again, that is a sign of misspecification. The model tries to explain the trade balance mostly with the measurement error.
The not simply means that the original code does not do what the paper claimed to be doing. They should have used the variance, but did not do so. Thus the square root.
I assumed that both the way of computing cutoff value and syntax are correct. Did you mean that I have already set initial value somewhere which resulted in the error message or I should set the value in its respective field to tackle the error?
Things got complicated. What could be the potential sources of misspecification and how can this issue be usually resolved? Is this something related to the observation equation for tby as attached? Trade balance to output ratio.pdf (305.7 KB)
Yes, that is the hard part. Understanding what causes this requires a lot of trial and error which model features could potentially account for this. What you could try is check the smoothed series for the trade balance without the measurement error (Dynare should produce that) and check if there is something immediately suspicious.
estimated_params_init(use_calibration); //Use their posterior as starting values for estimation; for measurement error, only the
stderr eps_tby_ME, sqrt(0.0175018482467928);
which is outside of the specified bounds.
No, I meant: estimate the model with the measurement error, but inspect the actual trade balance without the measurement error to see what the measurement error does.