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
Looping from last 10 numbers in a series
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- 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
You'll have to provide a little more detail.
But in general, you could do something like:
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
Re: Looping from last 10 numbers in a series
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.
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 (38 KiB) Viewed 4562 times
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: Looping from last 10 numbers in a series
I believe that what you're after doesn't require an explicit loop. For example,
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...
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
@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!
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 Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: Looping from last 10 numbers in a series
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).
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.
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
Thanks a lot!
Who is online
Users browsing this forum: No registered users and 42 guests