"logdata" must be used after "loglinear"

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

"logdata" must be used after "loglinear"

Postby ZBCPA » Wed Sep 09, 2015 11:26 am

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
ZBCPA
 
Posts: 101
Joined: Sat May 16, 2015 4:15 am

Re: "logdata" must be used after "loglinear"

Postby jpfeifer » Sun Sep 13, 2015 5:54 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: "logdata" must be used after "loglinear"

Postby ZBCPA » Mon Sep 14, 2015 1:49 am

jpfeifer wrote: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
ZBCPA
 
Posts: 101
Joined: Sat May 16, 2015 4:15 am

Re: "logdata" must be used after "loglinear"

Postby jpfeifer » Mon Sep 14, 2015 6:25 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: "logdata" must be used after "loglinear"

Postby ZBCPA » Thu Sep 17, 2015 11:14 am

jpfeifer wrote: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.


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=z*k(-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+alpha*ln(k(-1)) or lny=lnz*(lnk(-1))^alpha?

Best regards,
Huan
ZBCPA
 
Posts: 101
Joined: Sat May 16, 2015 4:15 am

Re: "logdata" must be used after "loglinear"

Postby jpfeifer » Thu Sep 17, 2015 7:44 pm

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: "logdata" must be used after "loglinear"

Postby ZBCPA » Fri Sep 18, 2015 5:15 am

jpfeifer wrote: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


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?

2. 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
ZBCPA
 
Posts: 101
Joined: Sat May 16, 2015 4:15 am

Re: "logdata" must be used after "loglinear"

Postby jpfeifer » Fri Sep 18, 2015 5:34 am

1. Yes, that's correct.
2. The observation equation in the original paper is
Code: Select all
g_y_net=log(yt)-log(yt-1)+log(gt)
where g_y is the net growth rate. I initially define
Code: Select all
g_y_gross=(yt/yt-1)*gt
where g_y_gross is defined as the gross growth rate. The loglinear command turns this into
Code: Select all
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
Code: Select all
gy_net=log(g_y_gross)

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: "logdata" must be used after "loglinear"

Postby ZBCPA » Fri Sep 18, 2015 7:56 am

jpfeifer wrote:1. Yes, that's correct.
2. The observation equation in the original paper is
Code: Select all
g_y_net=log(yt)-log(yt-1)+log(gt)
where g_y is the net growth rate. I initially define
Code: Select all
g_y_gross=(yt/yt-1)*gt
where g_y_gross is defined as the gross growth rate. The loglinear command turns this into
Code: Select all
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
Code: Select all
gy_net=log(g_y_gross)

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.


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

Best regards,
Huan
ZBCPA
 
Posts: 101
Joined: Sat May 16, 2015 4:15 am

Re: "logdata" must be used after "loglinear"

Postby ZBCPA » Mon Oct 05, 2015 1:02 am

jpfeifer wrote:1. Yes, that's correct.
2. The observation equation in the original paper is
Code: Select all
g_y_net=log(yt)-log(yt-1)+log(gt)
where g_y is the net growth rate. I initially define
Code: Select all
g_y_gross=(yt/yt-1)*gt
where g_y_gross is defined as the gross growth rate. The loglinear command turns this into
Code: Select all
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
Code: Select all
gy_net=log(g_y_gross)

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.


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=(dt*Xt-1 - dt+1*Xt)/rt (here rt is gross rate)

However, the TB data Generally does NOT appear Trend, so how can the equation above be altered to
Code: Select all
tbt=d-d(+1)*g/r
Do you mean TBt/Xt-1=tbt ?


2. Since TB in data has negative numbers, to make the steady state all positive (because of loglinear command), you define
Code: Select all
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 become
Code: Select all
log(log(tb_y)=log(log(tb))-logy

which is ACTUALLY(here tb_y and tb have no exp any more)
Code: Select all
log(tb_y)=logtb-logy
?


Best regards,
Huan
ZBCPA
 
Posts: 101
Joined: Sat May 16, 2015 4:15 am

Re: "logdata" must be used after "loglinear"

Postby jpfeifer » Sat Oct 10, 2015 7:12 am

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
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 9 guests