Page 1 of 2
Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 3:33 am
by diggetybo
Hello again,
I hope I'm not getting a bad reputation for flooding the forums haha. Hopefully others are learning from my questions too.
This question should be the last one for a long time, I'm almost finished with my paper. This question pertains to both estimation and data manipulation:
I have to know if eviews has any commands that compute or deal with PDL's. I noticed in other packages it goes by PDLREG, I didn't see that in the command list for eviews, but maybe it goes by a different name?
Alternatively, what would be even better is if I could code a new series to include in my LS regression. This way I can have my contemporaneous xj and a corresponding xj that is computed by one of the following operations (either the Almon or the Emerson):

- Polynomial Distributed Lag.png (53.54 KiB) Viewed 13965 times
No one ever told me that I would need programming skills for this class, so I'm learning as much as I can from the eviews programming tutorial whenever I have time. For my desired transformation as characterized above, the farthest I can get with the code for a distribution of 4 lags is...
Code: Select all
series x1_pdl = x1 + @sum(1,4) x1*@ap(4)
I was just guessing that Almon polynomial was ap, kind of like the Hodrick Prescott Filter is
. No such luck though.
If anyone knows the best way to use eviews to go about this procedure with a related built-in estimation setting or manipulating the data, please share.
Thanks
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 5:34 am
by trubador
If you searched for the keyword "polynomial distributed lags" in EViews' help files (or in the forum), then you would soon discover that EViews actually provides you with special expressions that can be used to specify and estimate such models.
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 7:47 am
by diggetybo
For what it's worth I had already looked at the help file, in fact eviews 6 & 7 help files, and couldn't find anything. Search resulted in 26 results for "Polynomial", but nothing about the actual feature. It was over 500 pages, I'm assuming it was the main help file.
Nonetheless, you were quite right about a useful thread in the forums. Here is a code I just found by eviews Gareth from 7 years ago:
Code: Select all
'create some data
create u 1000
series y=nrnd
series x=nrnd
'loop through combinations of lag (1 to 10) and degree of polynomial (1 to 5), finding the equation with the min aic
equation e1
!min_aic = 100000000
smpl 11 @last
for !deg=1 to 5
for !lag=!deg to 10
e1.ls y c pdl(x,!lag,!deg)
if e1.@aic < !min_aic then
!best_lag =!lag
!best_deg = !deg
!min_aic = e1.@aic
endif
next
next
So for a summed propensity of the lagged terms, like I mentioned previously, via transforming/creating a series using lags 1 through 9 my code would be something like:
Code: Select all
loop
for !deg=1 to 5
for !lag=!deg to 9
series x1_pdl = @sum(x1*(pdl(x1,!lag,!deg)))
endloop
I got an "illegal lag or index specification" error
It doesn't seem all that hard, but I guess looks are deceiving... or I'm just not adept enough. :?
My goal is incorporate discrete information from 9 lags in a single term to evaluate the summed propensity in an easier way. The only other way I know of is a pdl for each lag, but that could get out of hand if there are many variables.
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 8:04 am
by trubador
Now you know that the procedure is called PDL. Try searching for it in the help system/documentation.
I am not sure what you are trying to achieve. All I can say is that PDL is not a series expansion nor a filtering method and you cannot do the summation like that.
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 9:16 am
by diggetybo
I didn't check eviews guide II, that was the issue. I thought there was only one.
Anyway, it was a big help. Thank you for the tip. Actually I noticed eviews computes the sum of lags as part of the output, so I don't have to code anything.
The only question I felt wasn't addressed was eviews syntax for determining the order of the polynomial, if I had to guess, in eviews it would be as follows, given a series named "x1"
Code: Select all
ls x1 x1(-1) x1(-2) x1(-3) x1(-4) x1(-5) x1(-6) x1(-7) x1(-8) x1(-9) @trend @trend^2 @trend^3 @trend^4 @trend^5
then we evaluate which trends are significant?
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 10:55 am
by trubador
You do not have to guess, just look up for the correct syntax from the manual.
I do not follow your question. Polynomial Fit and Polynomial Distributed Lag are two separate things. Which one are you trying to accomplish?
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 4:47 pm
by diggetybo
I noticed in eviews guides both I and II, polynomial fit (which is what I'm trying to do) wasn't addressed . I looked very carefully, it covered pdl estimation, pdl theory, and pdl forecasting, however polynomial was only mentioned briefly and did not mention the eviews procedure.
My apologies if I have not been clear, please If you know which guide, post a link the .pdf or tell me the version number, I'm not sure which guide you're referring to.
Much appreciated.
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 4:55 pm
by startz
Polynomial Fit and Polynomial Distributed Lag are two separate things. Which one are you trying to accomplish?
^^^What Trubador said.
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 5:22 pm
by diggetybo
polynomial fit (which is what I'm trying to do)
Let me stress that again, sorry if I wasn't clear, I was just trying to take an educated guess. Didnt mean to cause confusion. Polynomial fit procedure is what I'm after, if it's short we could run through it here, else/if the eviews guide # that addresses this.
I agree the eviews guide is the most helpful, but I can't find it in there. There are many Eviews guides, so far I have looked through Eviews 6 guide, eviews 7 I & II In my experience crl+F doesn't lie very often.
Thanks for your understanding
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 5:37 pm
by startz
If you want to fit a polynomial, just do something like
There is nothing specifically built-in to decide the length of the polynomial.
Re: Polynomial Distributed Lag Terms
Posted: Mon Mar 09, 2015 6:50 pm
by diggetybo
Just when I thought I cleared up the confusion, I'm mistaken. I didnt mean the Polynomial Fit, I just meant to find a good fit for the PDL degree.
So I have read through the entire PDL procedure on the EViews Guide, and read as much about the eviews way on other websites.
I have then condensed my query to three simple questions below.
1. How does one go about determining the degree of a PDL in Eviews?
Consider this table that is computed after running a PDL from a similar package:

- Polynomial Order.png (25.75 KiB) Viewed 13884 times
We can test whether a degree is suitable or not by seeing which degree (of the polynomial) is significant. In the above example, a quadratic would do well.
that was what I meant by my earlier attempt to code a similar diagnostic regression -- just to reproduce something as in the above table.
2. Eviews guide points out that tests on significance are computed using the polynomial term gamma coefficients, if there is nothing built in for p values, how does eviews test for nulls for the betas? The t stat is provided, but what k (including beta in k?) to use when looking up the distribution?
3. Also is it possible to retrieve the polynomial formula? I want to reproduce it and plot it.
Again, sorry for the confusion, this time I have thought out my questions for a very long time, so as not to waste any more of your time.
Re: Polynomial Distributed Lag Terms
Posted: Tue Mar 10, 2015 3:58 am
by trubador
Regardless of the method you choose, you should also study "model selection" approaches as you also want to determine the most appropriate form. Information criteria can be very useful in this respect. You can also see an example of its use in Gareth's code that you posted earlier. Since this is a very broad topic, you should refer to textbooks.
I really cannot follow which analysis you want to do. The information you provided so far are equally split between PF (polynomial fit) and PDL (polynomial distributed lag). You seem to ask questions regarding PDL, but with PF in mind. So I think I'd bet on PF.
In PDL, it is the coefficients that are of the polynomial form, not the variables. The output from that other software also refers to PF, which you can do the same in EViews just as Startz have pointed out:
Code: Select all
ls y c x x^2 x^3
ls y = c(1) + c(2)*x + c(3)*x^2 + c(4)*x^3
Here, c or c(1) is the constant and corresponds to x**0 in your output. And at this point, I have to assume that you know how to read an output generated from an OLS estimation.
You can also use PF as a curve-fitting technique:
In the case of PDL, however, the main objective is to reduce the number of paremeters to be estimated in a distributed lag structure (as the name suggests):
Code: Select all
!k = 8 'lag length
!p = 4 'degree of the polynomial
!c = !k/2 'a constant to increase numerical stability of estimation
equation ols.ls y x(0 to -!k) 'OLS estimation
equation pdl.ls y c pdl(x,!k,!p) 'PDL estimation
coef betas = ols.@coefs 'estimated parameters of OLS
coef gammas = pdl.@coefs 'estimated parameters of PDL
coef(@rows(betas)) gammatobeta
for !j=1 to !k+1
gammatobeta(!j) = 0
for !i = 1 to !p+1
gammatobeta(!j) = gammatobeta(!j) + gammas(!i+1)*(!j-!c-1)^(!i-1) 'The relationship between betas and gammas
next
next
show betas
show gammatobeta
Lower part of the estimation output of PDL is comparable to that of OLS. And that is all I can say about this discussion.
Re: Polynomial Distributed Lag Terms
Posted: Thu Mar 12, 2015 5:41 am
by diggetybo
Hey,
Thanks for the input. I really do wish I was more clear with my procedure, that is my fault.
I tried the gamma to beta code you wrote trubador, it looks promising. I hate to drag this out, as you've really went above and beyond to help me make sense of things in eviews.
However, I am getting an error that reads "gammatobeta is not defined"
Im guessing that has something to do with a local programming variable that hasn't been declared, or maybe it's because I'm using eviews 6?
Re: Polynomial Distributed Lag Terms
Posted: Thu Mar 12, 2015 6:29 am
by trubador
It is probably due to @rows function. Just replace that line with the following:
Re: Polynomial Distributed Lag Terms
Posted: Thu Mar 12, 2015 6:59 am
by diggetybo
Hmm it still says "gammatobeta" is not defined:
Code: Select all
!k = 8 'lag length
!p = 4 'degree of the polynomial
!c = !k/2 'a constant to increase numerical stability of estimation
equation ols.ls y x(0 to -!k) 'OLS estimation
equation pdl.ls y c pdl(x,!k,!p) 'PDL estimation
coef betas = ols.@coefs 'estimated parameters of OLS
coef gammas = pdl.@coefs 'estimated parameters of PDL
coef(!k+1) gammatobeta
for !j=1 to !k+1
gammatobeta(!j) = 0
for !i = 1 to !p+1
gammatobeta(!j) = gammatobeta(!j) + gammas(!i+1)*(!j-!c-1)^(!i-1) 'The relationship between betas and gammas
next
next
show betas
show gammatobeta
Does it work for you? I hope it's not just me.