"logdata" must be used after "loglinear"

Dear Johhanes,

I find that in the new edition dynare 4.5, when I do bayesian estimation, the data I use are all logged (first difference),while the model block are non-linear, just like your code of “Real business cycles in emerging countries”, then I can use “logdata” command. However, it must be used with loglinear command,like

"estimestimation(datafile=data_argentina,
xls_range=G2:J107,
loglinear,
logdata,
mode_compute=6,
moments_varendo,
mh_nblocks=1,
mh_replic=1000000,
graph_format=(pdf,fig),
mode_check)

I can also use loglinear in the stoch_simul block BEFORE estimation block, the result will be same. Anyway, logdata command must follow loglinear command ,no matter “loglinear” appears after stoch_simul or appears after estimation.

Is that right?

Best regards,
Huan

Having the logdata command with loglinear does not make sense. The reason is that Dynare, upon encountering the loglinear statement takes the log of both the data and the model variables. The logdata command tells Dynare that the data is already in logs so that there is no point in taking the log again. However, without the loglinear statement, Dynare does not take the log so that using the logdata command is redundant.

Thanks for your reply.

  1. By that you mean, logdata should be used following loglinear command, but they should be used in DIFFERENT blocks, eg( loglinear is first used in stoch_simul, then logdata is used in estimation bolck which is AFTER stoch_simul.) Do I understand you correctly?

  2. You said “Having the logdata command with loglinear does not make sense.”, however, I did some experiments on your code of business cycles in emerging countries, and I find that if I use "estimation(loglinear,logdata,mh_nblocks=1,mode_compute=6…), even if I do NOT use estimated_params_init(use_calibration) command so that I set the initial values to be prior means, then I still could get very much similar results with the ones your original codes get interms of posterior mean and second moments. So theoretically this is wrong, but in practice, it might work?

Thanks again,
Huan

  1. logdata only affects the data. In stoch_simul no data is used, so you cannot use logdata there.
  2. No. What I said is that the logdata command is redundant if there is no loglinear statement. It does not harm because it will be ignored.

[quote=“jpfeifer”]1. logdata only affects the data. In stoch_simul no data is used, so you cannot use logdata there.
2. No. What I said is that the logdata command is redundant if there is no loglinear statement. It does not harm because it will be ignored.[/quote]

Dear Johhanes,
Many thanks.

Could I ask one more question about loglinear?

“A guide to secifying obsrvation equations for the estimation of dsge models” notes that " when using the loglinear option ,Dynare will use th logarithms in the background while you provide information on the orignial model with th unlogged variables".

So if in the model code, I write y=zk(-1)^alpha, then I use loglinear option, will dynare treat this eqution IN THE BACKGROUND to be ln(1/y)=ln(1/z) (ln(1/k(-1)))^alpha or lny=lnz+alphaln(k(-1)) or lny=lnz(lnk(-1))^alpha?

Best regards,
Huan

Why should it use the logarithm of the inverse? Of course it uses log of the original variables. That would be
y=z*k(-1)^alpha
becomes
exp(log_y)=exp(log_z)*exp(log_k(-1))^alpha

[quote=“jpfeifer”]Why should it use the logarithm of the inverse? Of course it uses log of the original variables. That would be
y=z*k(-1)^alpha
becomes
exp(log_y)=exp(log_z)*exp(log_k(-1))^alpha[/quote]

Many thanks.
1 . If I understand correctly, the code y=z*k(-1)^alpha with loglinear option will be treated to be exp(log_y)=exp(log_z)*exp(log_k(-1))^alpha by dynare in the background, **After That **dyare will use a linear Taylor approximation in logy , logz…finally the displayed results will be deviations of logy from logybar which also means the percentage diviation of y from ybar(ybar is the steady state of y), e.g.(result of +0.05 means that output increases 5 percent from steadystate output). Is that right?

  1. In your code of “real business cycles in emergin countries”, you use g_y=(yt/yt-1)*gt in the model block,then use loglinear option in stoch_simul block, then use logdata in estimation block. The actual measurement equation should be
    g_y=log(yt)-log(yt-1)+log(gt), which does not appear in your code. So dynare must have transformed mode code"g_y=(yt/yt-1)*gt "to be measurement equation"g_y=log(yt)-log(yt-1)+log(gt) "using loglinear and logdata commands.

Should be the process like the following:
Firstly ,after loglinear command, g_y=(yt/yt-1)*gt turns to be exp(logg_y)=exp(logyt)/exp(logyt-1)*exp(loggt), which is exp(logg_y)=exp(log(yt)-log(yt-1)+log(gt)), which is also logg_y=log(yt)-log(yt-1)+log(gt). Secondly, after logdata command, data g_y matches the model logg_y, so use g_y substitute logg_y ,so measurement equation becomes log(Yt/Yt-1)=g_y=log(yt)-log(yt-1)+log(gt).
Is that right?

Thanks again and again…

Best regards,
Huan

  1. Yes, that’s correct.
  2. The observation equation in the original paper is g_y_net=log(yt)-log(yt-1)+log(gt) where g_y is the net growth rate. I initially define

g_y_gross=(yt/yt-1)*gt where g_y_gross is defined as the gross growth rate. The loglinear command turns this into

logg_y_gross=log(yt)-log(yt-1)+log(gt). Now you have to consider that the gross and net growth rates are approximately related by

That’s why the two equations are equivalent. The logdata command only tells Dynare that the data is already a net growth rate so no transformation of the data is necessary.

[quote=“jpfeifer”]1. Yes, that’s correct.
2. The observation equation in the original paper is g_y_net=log(yt)-log(yt-1)+log(gt) where g_y is the net growth rate. I initially define

g_y_gross=(yt/yt-1)*gt where g_y_gross is defined as the gross growth rate. The loglinear command turns this into

logg_y_gross=log(yt)-log(yt-1)+log(gt). Now you have to consider that the gross and net growth rates are approximately related by

That’s why the two equations are equivalent. The logdata command only tells Dynare that the data is already a net growth rate so no transformation of the data is necessary.[/quote]

What you explained is so clear. Thank you so much!

Best regards,
Huan

[quote=“jpfeifer”]1. Yes, that’s correct.
2. The observation equation in the original paper is g_y_net=log(yt)-log(yt-1)+log(gt) where g_y is the net growth rate. I initially define

g_y_gross=(yt/yt-1)*gt where g_y_gross is defined as the gross growth rate. The loglinear command turns this into

logg_y_gross=log(yt)-log(yt-1)+log(gt). Now you have to consider that the gross and net growth rates are approximately related by

That’s why the two equations are equivalent. The logdata command only tells Dynare that the data is already a net growth rate so no transformation of the data is necessary.[/quote]

Dear Johhanes,

Could I ask two more questions about trade-balance in your code?

  1. 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

tbt=d-d(+1)*g/r Do you mean TBt/Xt-1=tbt ?

  1. 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 ?

Best regards,
Huan

  1. The trade balance in the data should be cointegrated with output. Thus, there is a trend (though it may be hard to spot)
  2. You are not supposed to loglinearize the trade balance. You should linearize it

Hi prof Pfeifer, I have a similar question but not on trade balance, instead, regarding government wedge (calculated in the data as g = log(government spending + net export)) in BCA.

For the economy I am considering, (government spending + net export) in the data is sometimes negative, so I cannot take logs. Thus, for example, given log_g_t_data = CKM_data.g; in your replications code, I am unable to compute CKM_data.g in the first place.

I am thinking of other options. I read a paper where the author appears to use different detrending methods for the same model. All variables in the data are log deviations from their trend except trade balance which is detrended by output.

But I don’t have his codes, so not sure if that’s what he actually did in DYNARE, where given varobs y x l g_y;, for example, y, x, l are log deviations from trend and g_y is just (government spending + net export)/y in the data. How may I modify the BCA mod file accordingly?

Something like this?

var g_y g c l...

model;
exp(c)+exp(log(g))+... instead of exp(c)+exp(g)+...
...
log(g_y) = log(g)/y

Thus, is this where one needs to use the loglinear and logdata options of Dynare? Or maybe I can keep same mod file and just replace g = log(government spending + net export) in the data with g = (government spending + net export)/y? Thanks!

No, you need to match the data in the model and the data file. If in your data file you have g/y, both originally in levels, then in the mod-file

 var g_y g c l y...

model;
exp(y)=exp(c)+g+... instead of exp(y)+exp(c)+exp(g)+...
...
g_y = g/exp(y)

That way, g is kept in levels and can be negative (note that you could also have it defined in logs as Dynare will do a linear approximation) and in the definition of the ratio g_y, the exp undoes the implicit logging of the exp()-substitution to give you also the ratio of the levels in the model.

I see. Thanks!! Then I can compute government wedge (G_t ) from the non-linear equation g_y = g/exp(y) like:

G_t = g_y_t_data * exp(log_y_t_data)

In the replication of “García-Cicco, Javier and Pancrazi, Roberto and Uribe, Martín (2010): Real Business Cycle in Emerging Countries”, you define trade balance to output ratio as follows:

%10. Definition trade-balance to output ratio
log(tb_y) = log(tb)/y;

So here, log(tb)/y is a ratio of logs in the model. What is tb_y = TBY in the data? A ratio of logs or levels?

If tb_y is a ratio of logs in the data, then why take logs again (i.e., log(tb_y)) under model; block?

And if tb_y is a ratio of levels in the data, then why don’t we have log(tb_y) = log(tb) - y; instead so that there is a match between model and data…I cannot see the match yet.

Screenshot from 2021-10-18 20-13-53

The log here is to make sure that the loglinear-option does not take the log. That is for replication purposes. In the original replication files

%Note: we take a linear, rather than log-linear, approximation with respect to tb, the trade balance)

The loglinear-option induces Dynare to essentially do an exp()-substitution. The log an the exp() cancel to leave the TB unaffected.

Essentially, in a clean file we should have

TB_Y=TB /Y

as the ratio of levels.

Hi prof. Pfeifer, may I ask this question. Because I am unable to compute log_g_t_data = log(government spending + net export) in the data in BCA, I have done the following:

  1. I have replaced g with c in the data (i.e., varobs y x l c; instead of varobs y x l g;)
  2. So I calculate government wedge in the model, rather than in the data (i.e., log_g_t = log_g_ss+(exp(log_y_ss)*(log_y_t_data-log_y_ss)-exp(log_x_ss)*(log_x_t_data-log_x_ss) - exp(log_c_ss)*(log_c_t_data-log_c_ss))/exp(log_g_ss);
  3. Where log_c_t_data is from the data (i.e., log_c_t_data = CKM_data.c;)
  4. I then recover consumption in levels as follows, C_t = exp(log_c_t_data);

This approach works, right? Thus, government wedge can be computed in the model (rather than in the data) using data on y, c, and x.

I am not sure I understand the problem. After all, the model infers the wedges. So pretty much any combination of observables should work.

1 Like