Generating a New Variable that Includes a Lag of Itself

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

einsler
Posts: 6
Joined: Fri Feb 19, 2010 1:20 pm

Generating a New Variable that Includes a Lag of Itself

Postby einsler » Fri Feb 19, 2010 1:41 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13585
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Fri Feb 19, 2010 2:05 pm

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?

einsler
Posts: 6
Joined: Fri Feb 19, 2010 1:20 pm

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

Postby einsler » Fri Feb 19, 2010 2:15 pm

The first value of v is equal to the first value of e

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13585
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Fri Feb 19, 2010 2:18 pm

Code: Select all

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

einsler
Posts: 6
Joined: Fri Feb 19, 2010 1:20 pm

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

Postby einsler » Fri Feb 19, 2010 2:34 pm

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13585
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Fri Feb 19, 2010 3:00 pm

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)

einsler
Posts: 6
Joined: Fri Feb 19, 2010 1:20 pm

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

Postby einsler » Tue Feb 23, 2010 9:13 am

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13585
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Tue Feb 23, 2010 9:18 am

change

Code: Select all

smpl @first+1 @last
to be

Code: Select all

smpl 5 42


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests