Page 1 of 1
Looping from last 10 numbers in a series
Posted: Tue Jan 10, 2017 9:59 am
by BigD
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
Re: Looping from last 10 numbers in a series
Posted: Tue Jan 10, 2017 10:15 am
by EViews Gareth
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
Re: Looping from last 10 numbers in a series
Posted: Tue Jan 10, 2017 12:15 pm
by BigD
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.
Re: Looping from last 10 numbers in a series
Posted: Tue Jan 10, 2017 12:42 pm
by EViews Matt
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...
Re: Looping from last 10 numbers in a series
Posted: Tue Jan 10, 2017 1:11 pm
by BigD
@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!
Re: Looping from last 10 numbers in a series
Posted: Tue Jan 10, 2017 3:14 pm
by EViews Matt
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.
Re: Looping from last 10 numbers in a series
Posted: Fri Jan 13, 2017 7:34 am
by BigD
Thanks a lot!