### HDecomp (historical decomposition)

Posted:

**Thu Apr 12, 2012 9:57 am**This thread is about the HDecomp add-in, written by Eren Ocakverdi (Trubador), that performs historical decomposition on a VAR object.

Page **1** of **3**

Posted: **Thu Apr 12, 2012 9:57 am**

This thread is about the HDecomp add-in, written by Eren Ocakverdi (Trubador), that performs historical decomposition on a VAR object.

Posted: **Thu Feb 27, 2014 9:26 am**

Hi,

I don't understand how to interpret what each column of the histmat that I get refers to. Basically, all I want to do is find a measure of the output gap using hdecomp from the Blanchard Quah model (figure 8 in the BQ paper).

So HDdecomp creates a matrix of n(n+1) columns, where n is the number of variables in a VAR, a n(n+1) matrix of series.

The BQ program in the example file stops short of extracting the effect of demand shocks on output.

Perhaps then let me reference the case study provided by trubadour.

His VAR had the following variables: Dlog(imported price index), Dlog(gdp) and Dlog(cpi).

And there are three structural disturbances:

1)a component that affects all three variables

2) " that doesnt affect Dlog(imported price index)

3) " that affects only Dlog(cpi)

with the corresponding lr restrictions.

He pulls out the 12th column from the matrix, and that corresponds to core inflation. Could you help me understand the logic of that -the ordering?

Thanks

I don't understand how to interpret what each column of the histmat that I get refers to. Basically, all I want to do is find a measure of the output gap using hdecomp from the Blanchard Quah model (figure 8 in the BQ paper).

So HDdecomp creates a matrix of n(n+1) columns, where n is the number of variables in a VAR, a n(n+1) matrix of series.

The BQ program in the example file stops short of extracting the effect of demand shocks on output.

Perhaps then let me reference the case study provided by trubadour.

His VAR had the following variables: Dlog(imported price index), Dlog(gdp) and Dlog(cpi).

And there are three structural disturbances:

1)a component that affects all three variables

2) " that doesnt affect Dlog(imported price index)

3) " that affects only Dlog(cpi)

with the corresponding lr restrictions.

He pulls out the 12th column from the matrix, and that corresponds to core inflation. Could you help me understand the logic of that -the ordering?

Thanks

Posted: **Thu Feb 27, 2014 1:50 pm**

For each series, there is a base forecast plus the total impact of structural shocks. Hence, the matrix dimension is equal to n(n+1). In your case, there are two variables (unemployment and gdp), so histmat will be a 2x3 matrix. Since gdp is the first variable, columns 1, 2 and 3 will correspond to the base forecast for GDP, historical impact of the first shock and the historical impact of the second shock, respectively.

Figure 8 of the paper is called "Output fluctuations due to demand". If this is what you want, then the third column of the histmat will be of your interest. However, an output gap estimation would require the construction of potential gdp first. And this would require the use of all three columns.

As a final remark, please be careful in replicating the results of the original paper since there are some data preparation steps like demeaning and detrending.

Figure 8 of the paper is called "Output fluctuations due to demand". If this is what you want, then the third column of the histmat will be of your interest. However, an output gap estimation would require the construction of potential gdp first. And this would require the use of all three columns.

As a final remark, please be careful in replicating the results of the original paper since there are some data preparation steps like demeaning and detrending.

Posted: **Fri Feb 28, 2014 5:08 am**

Hi Trubador,

Thank you for the clarification. On the point you made on constructing potential output first: if Histmatâ€™s column 3 is the demand component of output, then it should correspond precisely to potential minus actual (assuming demand shocks do not affect potential GDP at all).

Actually, not quite right-the third column of histmat is the first difference of the demand component of output, so presumably one has to pick a point where actual=output and un-difference.

Something quite important I would like to draw your attention on: the third column of histmat looks nothing like figure 8 (output fluctuations due to demand) in the original paper.

I first thought that might be something to do with BQ splitting the gdp data in two samples, filtering the unemployment rate, putting a dummy in, an whatever other small adjustments. Except that these changes must be very, very slight, and in fact the IRFs from the Eviews sample program you wrote correspond pretty much exactly to those in the article. So something else is amiss here, but I cannot think what.

Do you have any suggestions?

By the way, I've just looked at the RATS' replication code for that paper, and from I can see what that uses for figure 8 is indeed the third column of the historical decompostion matrix (without any adjustment of sorts) I've attached the program output from that code to this post.

As a check to see whether I was hallucinating, I took the series that they get after detrending, de-meaning etc and that they put into the VAR (gdpadjust and uradjust) and still what I get from the historical decomposition**in eviews **isn't what they get. I'm puzzled as I have to have this model working with eviews.

I look forward to hearing from you.

Regards

Thank you for the clarification. On the point you made on constructing potential output first: if Histmatâ€™s column 3 is the demand component of output, then it should correspond precisely to potential minus actual (assuming demand shocks do not affect potential GDP at all).

Actually, not quite right-the third column of histmat is the first difference of the demand component of output, so presumably one has to pick a point where actual=output and un-difference.

Something quite important I would like to draw your attention on: the third column of histmat looks nothing like figure 8 (output fluctuations due to demand) in the original paper.

I first thought that might be something to do with BQ splitting the gdp data in two samples, filtering the unemployment rate, putting a dummy in, an whatever other small adjustments. Except that these changes must be very, very slight, and in fact the IRFs from the Eviews sample program you wrote correspond pretty much exactly to those in the article. So something else is amiss here, but I cannot think what.

Do you have any suggestions?

By the way, I've just looked at the RATS' replication code for that paper, and from I can see what that uses for figure 8 is indeed the third column of the historical decompostion matrix (without any adjustment of sorts) I've attached the program output from that code to this post.

As a check to see whether I was hallucinating, I took the series that they get after detrending, de-meaning etc and that they put into the VAR (gdpadjust and uradjust) and still what I get from the historical decomposition

I look forward to hearing from you.

Regards

Posted: **Fri Feb 28, 2014 5:44 pm**

I am not going to delve into a deep discussion on the issues you mention, but they are not that much straightforward. Original paper has a very nice and a detailed discussion. And now you can carry out those analyses in EViews with the help of this add-in. Replicating such a seminal paper is not an easy task, but for the sake of further clarifying the use of this add-in I've prepared the code below with the data you have supplied:

Code: Select all

`'Open the file`

wfopen ratsoutput.wf1

'Create a copy of the page to compare the results

pagecopy

'Make the necessary transformations

series loggnp = log(gnp)

series loggd = log(gd87)

series logrgnp = loggnp - loggd + log(100)

series dlogrgnp = 100*d(logrgnp)

'Generate the dummies for two regimes

series dummy1 = @before("1974q1")

series dummy2 = @after("1974q1")

'Adjust the gdp series with respect to different regimes (demeaning)

equation eq1.ls dlogrgnp dummy1 dummy2

series gdpadjust = resid

series means_from_gnp = dummy1*c(1) + dummy2*c(2)

'Remove the trend in unemployment (detrending)

equation eq2.ls lhmur c @trend

series uradjust = resid

eq2.fit trend_from_ur

'Build and estimate the VAR Model

var bq.ls 1 8 gdpadjust uradjust @ c

%varsmpl = bq.@smpl

'Long-run restriction matrix

matrix(2,2) matc = NA

matc(1,2) = 0

'Estimate structural factorization

bq.svar(rtype=patlr,namelr=matc)

'Get the estimated factor

matrix bqfactor = bq.@svarbmat

'Adjust the sign

if bqfactor(1,2)<0 then

vector sign = @ones(2)

sign(2) = -1

bqfactor = bqfactor*@makediagonal(sign)

endif

'Undo the degree-of-freedom adjustment, which is the default estimation in EViews

!dofadjust = (bq.@regobs-(bq.@ncoefs/bq.@neqn))/bq.@regobs

bqfactor = bqfactor*@sqrt(!dofadjust)

'Carry out the historical decomposition

bq.hdecomp(imp=7,fname=bqfactor)

'Retrieve the result as series

!k = 0

for !i = 1 to 2

for !j = 1 to 3

!k = !k+1

vector v_!k = @columnextract(histmat01,!k)

mtos(v_!k,histdecomp_!j_!i_)

delete v_!k

next

next

'Generate the series of interest

histdecomp_1_1_ = histdecomp_1_1_ + means_from_gnp

histdecomp_1_2_ = histdecomp_1_2_ + trend_from_ur

for !j = 1 to 3

histdecomp_!j_1_ = @cumsum(histdecomp_!j_1_,%varsmpl)/100

next

histdecomp_1_1_ = histdecomp_1_1_ + @elem(logrgnp,"1950q1")

series lessdemand = histdecomp_1_1_ + histdecomp_2_1_

'Selected graphical output from the paper

freeze(figure1_and_2) bq.impulse(40,a,g,imp=user,fname=bqfactor)

show figure1_and_2

graph figure7.line lessdemand

figure7.label(r) Output fluctuations absent demand

show figure7

graph figure8.line histdecomp_3_1_

figure8.label(r) Output fluctuations due to demand

figure8.recshade

figure8.draw(line, left) 0

show figure8

Posted: **Tue Apr 29, 2014 9:11 am**

Hi,

Does anybody know what the error message "(1002,1) is not a valid index for matrix SHOCK" stands for when using the add-in? I have pm'ed trubador with more info on this problem, but if someone knows how to solve this problem off the top of one's head, I would greatly appreciate the help on this problem.

Thank you in advance,

Regards,

Vincent

Does anybody know what the error message "(1002,1) is not a valid index for matrix SHOCK" stands for when using the add-in? I have pm'ed trubador with more info on this problem, but if someone knows how to solve this problem off the top of one's head, I would greatly appreciate the help on this problem.

Thank you in advance,

Regards,

Vincent

Posted: **Wed Apr 30, 2014 12:54 pm**

That is because you are trying to use the add-in for panel data, which would not work. And please see the following post before going any further on your study: VAR estimation in a Panel setting

Posted: **Thu Jun 05, 2014 4:36 am**

Hi guys,

I'm trying to replicate the BQ results in figure 8 of their paper (as was the gentleman above).

I've got the original data in the attached workfile and cannot, for the life of me, get the results to match using hdecomp.

I'd be very grateful if you could advise me where I am going wrong or if there is something wrong with the hdecomp function?

Thanks,

Jamie

I'm trying to replicate the BQ results in figure 8 of their paper (as was the gentleman above).

I've got the original data in the attached workfile and cannot, for the life of me, get the results to match using hdecomp.

I'd be very grateful if you could advise me where I am going wrong or if there is something wrong with the hdecomp function?

Thanks,

Jamie

Posted: **Thu Jun 05, 2014 5:26 am**

Just run the program written by trubador, it will give the output for figure 8

Posted: **Thu Jun 05, 2014 5:45 am**

Hi fregensberg,

I ran the Hdecomp addin on the VAR, selected structural decomposition and looked at the histmat.

None of the columns looks anything like figure 8, whether the shocks are accumulated or not.

If you don't mind me asking, does it work on your machine?

Thanks,

Jamie

I ran the Hdecomp addin on the VAR, selected structural decomposition and looked at the histmat.

None of the columns looks anything like figure 8, whether the shocks are accumulated or not.

If you don't mind me asking, does it work on your machine?

Thanks,

Jamie

Posted: **Thu Jun 05, 2014 6:17 am**

Not the add-in. The code in one of the previous posts in this thread: viewtopic.php?f=23&t=5901#p33926

Posted: **Thu Aug 14, 2014 5:23 pm**

Hi Trubador,

Thanks for this very useful add-in and the replication code.

I have a question, why do you adjust the sign of the BQfactor in the code? Thanks

C.

Thanks for this very useful add-in and the replication code.

I have a question, why do you adjust the sign of the BQfactor in the code? Thanks

C.

Posted: **Wed Oct 08, 2014 5:20 pm**

Does anybody know how to use this add-in when the VAR contains Cointegration relationships. I tried but I receive the error message "RESGR is not defined". Thanks in advance for your attention.

Posted: **Wed Oct 22, 2014 12:20 am**

The add-in works on the structural factorization matrix, which EViews does not estimate for VECs and BVARs at the moment.

Posted: **Fri Nov 14, 2014 5:26 am**

Hi Trubador,

Thanks for making historical decomposition available in Eviews.

I have a question. Say we have 3 variables: inflation, output gap and exchange rate. Then, in the histmat we will have 12 columns. In my understanding, the first columns is forecast base of inflation, the second column is the first structural shock (inflation shock), the third column is second structural shock (output gap), and 4th column is the third structural shock (exchange rate). What about column 5 to 8? Column five is the forecast base of output gap right? Is column 6 represents structural shock output gap, column 7 represents structural shock of inflation and column 8 represents structural shock of exchange rate?

looking forward for your kindly explanations.

Thanks for making historical decomposition available in Eviews.

I have a question. Say we have 3 variables: inflation, output gap and exchange rate. Then, in the histmat we will have 12 columns. In my understanding, the first columns is forecast base of inflation, the second column is the first structural shock (inflation shock), the third column is second structural shock (output gap), and 4th column is the third structural shock (exchange rate). What about column 5 to 8? Column five is the forecast base of output gap right? Is column 6 represents structural shock output gap, column 7 represents structural shock of inflation and column 8 represents structural shock of exchange rate?

looking forward for your kindly explanations.