loop and time series control

For questions regarding programming in the EViews programming language.

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

coder_79
Posts: 6
Joined: Thu Jan 31, 2013 11:03 am

loop and time series control

Postby coder_79 » Thu Jan 31, 2013 11:29 am

A very simple, intuitive conversion from returns to index levels
Quarterly data runs from 1987Q1 to 2011Q4
program shown as below

**************************************************************************************************************************
series level

for !i=1 to 100
if !i=1 then
level.fill(o=1987Q1) @elem(return, "1987Q1")/100+1 ' returns are in percentage, base level of 1986Q4 equals 1
else
level.fill(o=1986Q4+!i) (@elem(level, 1986Q4+!i-1)*(1+@elem(return, 1986Q4+!i)/100))
endif
next
***************************************************************************************************************************

however, eviews reports error for 1986Q4+!i, saying invalid date.
tried several date functions, including @otod, cannot figure it out.
Any one can help? Thanks.

coder_79
Posts: 6
Joined: Thu Jan 31, 2013 11:03 am

Re: loop and time series control

Postby coder_79 » Thu Jan 31, 2013 11:41 am

I'm using eviews 7.2

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

Re: loop and time series control

Postby EViews Gareth » Thu Jan 31, 2013 11:53 am

The precise fix to your code is:

Code: Select all

for !i=1 to 100 if !i=1 then level.fill(o=1987Q1) @elem(return, "1987Q1")/100+1 ' returns are in percentage, base level of 1986Q4 equals 1 else %date1 = @datestr(@dateadd(@dateval("1986q4", "YYYY[q]Q"),!i-1,"q")) %date2 = @datestr(@dateadd(@dateval("1986q4", "YYYY[q]Q"),!i,"q")) level.fill(o=%date2) (@elem(level, %date1)*(1+@elem(return, %date2)/100)) endif next
However that is a silly way to go about things. You're better off doing this:

Code: Select all

smpl 1987q1 1987q1 series level2 = return/100+1 smpl 1987q2 @last level2 = level(-1)*(1+return/100) smpl @all

coder_79
Posts: 6
Joined: Thu Jan 31, 2013 11:03 am

Re: loop and time series control

Postby coder_79 » Thu Jan 31, 2013 12:07 pm

Thank you very much!

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

Re: loop and time series control

Postby EViews Gareth » Thu Jan 31, 2013 12:20 pm

If you want to get really fancy, you can do it in just one line:

Code: Select all

series level3 = @recode(level3(-1)=na,return/100+1, level(-1)*(return/100+1))


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests