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.
loop and time series control
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Re: loop and time series control
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
The precise fix to your code is:
However that is a silly way to go about things. You're better off doing this:
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
Code: Select all
smpl 1987q1 1987q1
series level2 = return/100+1
smpl 1987q2 @last
level2 = level(-1)*(1+return/100)
smpl @all
Re: loop and time series control
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
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))
Who is online
Users browsing this forum: No registered users and 2 guests
