Page 1 of 1

Generating a New Variable that Includes a Lag of Itself

Posted: Fri Feb 19, 2010 1:41 pm
by einsler
I would like to generate a series of the following formula:

v = 0.606 * v(-1) + e

e is simply the residual of a previous regression, which I can obtain from resid, but the problem with this formula is that it contains a lag of itself - the v(-1) term. Is there any programming code that can take care of this problem?

Thank you very much for your help.

- Eric

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Fri Feb 19, 2010 2:05 pm
by EViews Gareth
Well, you'll have to decide how you want to handle the problem mathematically before you can decide how to handle it programmatically.

What do you want the first value of v to be equal to?

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Fri Feb 19, 2010 2:15 pm
by einsler
The first value of v is equal to the first value of e

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Fri Feb 19, 2010 2:18 pm
by EViews Gareth

Code: Select all

series v=e smpl @first+1 @last v=0.606*v(-1)+e smpl @all

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Fri Feb 19, 2010 2:34 pm
by einsler
Thank you so much Gareth. I will try this soon and I expect it to work.

I had assumed that I needed a genr command. I am not familiar with the series command.

Also, would the code still work if I replaced the 0.606 with a coefficient from the last regression - c(3) or c(2) for example?

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Fri Feb 19, 2010 3:00 pm
by EViews Gareth
SERIES and GENR are interchangeable - they're the same command. It's a matter of personal preference that I use SERIES, but a lot of the others around here use GENR.

And yes, it would work if you replace 0.606 with c(1)

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Tue Feb 23, 2010 9:13 am
by einsler
I just tested the code that you gave me and it just produced a vector of NA's. I think it may be due to the fact that the samples might be off. Here is the code that I used:

Code: Select all

smpl 1 42 genr lninvpc=log(invpc) ls lninvpc c t genr lninvpc_detrend=lninvpc-(c(1)+c(2)*t) ls lninvpc_detrend c gprice lninvpc(-1) gprice(-1) smpl 4 42 ls lninvpc_detrend c gprice lninvpc_detrend(-1) gprice(-1) genr ehat=resid genr vhat=ehat smpl @first+1 @last vhat=c(3)*vhat(-1)+ehat smpl @all
The first value of ehat is actually the fourth value in the total data set. Is there a way to correct for this in the code?

Re: Generating a New Variable that Includes a Lag of Itself

Posted: Tue Feb 23, 2010 9:18 am
by EViews Gareth
change

Code: Select all

smpl @first+1 @last
to be

Code: Select all

smpl 5 42