Looping from last 10 numbers in a series

For questions regarding programming in the EViews programming language.

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

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Looping from last 10 numbers in a series

Postby BigD » Tue Jan 10, 2017 9:59 am

Hi,

I was wondering how to loop form the last 10 numbers in a series as I am creating a program to validate those numbers with another series from another database.

Thanks

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

Re: Looping from last 10 numbers in a series

Postby EViews Gareth » Tue Jan 10, 2017 10:15 am

You'll have to provide a little more detail.

But in general, you could do something like:

Code: Select all

for !i=1 to 10
smpl @last-!i+1 @last-!i+1
'stuff here
next
Follow us on Twitter @IHSEViews

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Re: Looping from last 10 numbers in a series

Postby BigD » Tue Jan 10, 2017 12:15 pm

The series will have a date and value (see attachment) and I am going to find the percentage difference between one series and another one using @elem.
But, I only want to find the percentage difference for the last 10 or so values in both series. For example, find the percentage difference for the years 2005 - 2015 for both series where they both start at 2001.
Attachments
A series.PNG
A series.PNG (38 KiB) Viewed 4562 times

EViews Matt
EViews Developer
Posts: 563
Joined: Thu Apr 25, 2013 7:48 pm

Re: Looping from last 10 numbers in a series

Postby EViews Matt » Tue Jan 10, 2017 12:42 pm

I believe that what you're after doesn't require an explicit loop. For example,

Code: Select all

smpl @last-9 @last
series z = 100 * (y - x) / x

The above calculates the percentage difference between series x and y (relative to x) for the last ten observations. The generated series z will have NAs for all earlier observations. If you don't want the results in a series object, then that's another matter...

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Re: Looping from last 10 numbers in a series

Postby BigD » Tue Jan 10, 2017 1:11 pm

@Eviews_Matt
Thanks for the suggestion. However, are you able to also add in text to the series beside the percent difference?
I'm doing a certain threshold (say 5% difference) that says if the percent difference is over 5%, then a text should say "Values are too different", otherwise say "OK". I know an if/else statement is required (maybe a loop too) for this but I'm just wondering if text can also be inserted beside the values.
I'm pretty new to all this.
EDIT:
I've created a group and looped through percentdiff for my if statements.

Thanks!

EViews Matt
EViews Developer
Posts: 563
Joined: Thu Apr 25, 2013 7:48 pm

Re: Looping from last 10 numbers in a series

Postby EViews Matt » Tue Jan 10, 2017 3:14 pm

A series object cannot hold text, but you could use a two-column table object to hold the numeric values and text side-by-side. You can quickly create such a table from a series object (for the numbers) and an alpha object (for the text).

Code: Select all

smpl @last-9 @last
series pdiff = 100 * (y - x) / x
alpha label = @recode(@abs(pdiff) <= 5, "OK", "Values are too different")
group tmp pdiff label
freeze(results) tmp

Building on my previous example, the above produces a table object named results with the percentage differences and text descriptions. You could customize the look of the table afterwards, if need be.

BigD
Posts: 28
Joined: Wed Jan 04, 2017 7:05 am

Re: Looping from last 10 numbers in a series

Postby BigD » Fri Jan 13, 2017 7:34 am

Thanks a lot!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 42 guests