Quadratic trend for each country in the panel

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
Gilbril
Posts: 78
Joined: Thu Aug 19, 2010 2:00 pm

Quadratic trend for each country in the panel

Unread post by Gilbril »

Dear Tom,

I do have a panel with 13 countries. I do want to calculate the output gap for each country individually.

I used the sample code from the user guide to do data transformations for each item.

It works fine for th HP-filtered output gap, but for the output gap constructed using the quadratic trend it just produces the output gaps for the last country in the panel. Also replacing the output gap from the j loop intop the i loop. Does not change the result.

Where is the mistake?

panel(group=cid,id=vid,identries=identries)
do i=1,%size(vid)
comp a=0
*loop for individuals
do j=1,%size(identries(i))
* loop over entries within individuals
compute it=identries(i)(j)
FILTER(TYPE=HP,TUNING=1600) GDPINDEX i//ibegin i//iend HP_GDP
set ygap =GDPindex-HP_GDP
comp a = a+1
comp trend(a+(i-1)*80) = a
comp trend2(a+(i-1)*80) = a*a
linreg gdpindex i//ibegin i//iend ygapsq
# constant trend trend2
end do j

end do i


Thanks a lot

Gilbril
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Quadratic trend for each country in the panel

Unread post by TomDoan »

You have the HP-filter calculation and the LINREG inside your J loop which doesn't look right.

If you want distinct trends for each individual, just do

set trend = %period(t)
set trend2 = trend^2

which you only need to do once, so you can get rid of the entire J loop.
Gilbril
Posts: 78
Joined: Thu Aug 19, 2010 2:00 pm

Re: Quadratic trend for each country in the panel

Unread post by Gilbril »

Dear Tom, I did like you suggested the code is now (look below) but , when I print HP_gdp and ygapsq.The series for the quadratic output gap ygapsq just contains numbers for the last individual 13.
Whereas for HP_GDP I do find correctly a trend for each of the 13 individuals. I dont know why the residuals for the quadratic trend are just calculated for the last individual.

panel(group=cid,id=vid,identries=identries)
do i=1,%size(vid)
comp a=0
*loop for individuals

FILTER(TYPE=HP,TUNING=1600) GDPINDEX i//ibegin i//iend HP_GDP
set ygap =GDPindex-HP_GDP
set trend = %period(t)
set trend2 = trend^2
linreg gdpindex i//ibegin i//iend ygapsq
# constant trend trend2
end do i

print / HP_GDP ygapsq

Thanks
Gilbril
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Quadratic trend for each country in the panel

Unread post by TomDoan »

The residuals from a LINREG are cleared out each time, so you can't put together a series in pieces using just the LINREG. You want something like:

linreg gdpindex i//ibegin i//iend
# constant trend trend2
set ygapsq i//ibegin i//iend = %resids

Why do you think that the deviation from the HP filter will have a quadratic trend worth removing?
Post Reply