How do I convert the date of the last observation in a time series so that I can use the addtext instruction in a graph? The purpose being to update the range of data automatically in a programme. For example, suppose that I want to use the text "Data 1999-lastdate".
I've tried x.@last in various ways without success.
Using last observation in graph text
Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator
-
- EViews Developer
- Posts: 870
- Joined: Tue Sep 16, 2008 3:50 pm
Re: Using last observation in graph text
You are going to have to be more explicit. @last will return the observation label of the last non NA value in the series.
What are you seeing that appears to be incorrect?
What are you seeing that appears to be incorrect?
Re: Using last observation in graph text
The problem isn't getting the last observation, it's concatenating that value with text so that the range displayed in the graph text is updated correctly.
For example, suppose the basic text is "Temperature from 1850-". I want to add the date of the last observation to that text so that the range of the current data is updated each time the data is updated. If the previous last observation was 2016 and the new data is 1850 to 2017, I want the range to change automatically from 1850-2016 to 1850-2017 in the graph text. At present, I do this manually before I run a programme.
I have numerous programmes for which this could be use.
I hope this clarifies what I'm looking for.
For example, suppose the basic text is "Temperature from 1850-". I want to add the date of the last observation to that text so that the range of the current data is updated each time the data is updated. If the previous last observation was 2016 and the new data is 1850 to 2017, I want the range to change automatically from 1850-2016 to 1850-2017 in the graph text. At present, I do this manually before I run a programme.
I have numerous programmes for which this could be use.
I hope this clarifies what I'm looking for.
-
- EViews Developer
- Posts: 870
- Joined: Tue Sep 16, 2008 3:50 pm
Re: Using last observation in graph text
Try using the following code to get the string representation of the last year in the workfile
and then you could append that to your final string using
Code: Select all
%s=@otod(@obsrange)
%last_year=@datestr(@dateval(%s), "YYYY")
and then you could append that to your final string using
Code: Select all
%text = "Temperature from 1850-" + %last_year
Re: Using last observation in graph text
Hi
This works except it puts quotes about the last date, i.e., "2017" rather than 2017 making the label look a little odd.
This works except it puts quotes about the last date, i.e., "2017" rather than 2017 making the label look a little odd.
Re: Using last observation in graph text
Hi
I just tried @stripquotes to see if this fixed things but it didn't, presumably because I used %last_year still.
I just tried @stripquotes to see if this fixed things but it didn't, presumably because I used %last_year still.
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13315
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Using last observation in graph text
Are you sure you've copied every thing correctly?
Code: Select all
wfcreate a 1850 2017
series x=nrnd
freeze(g) x.line
%s = @otod(@obsrange)
%last_year = @datestr(@dateval(%s), "YYYY")
%text = "Temperature from 1850-" + %last_year
g.addtext(ac) {%text}
show g
Follow us on Twitter @IHSEViews
Re: Using last observation in graph text
Yes I copied it straight from here (using copy instruction). Will try again when I get back to the laptop.
Re: Using last observation in graph text
Hi
I tried it and it worked. What I didn't realise was that I had to use %text as the text for the graph.
So thanks for all this.
I tried it and it worked. What I didn't realise was that I had to use %text as the text for the graph.
So thanks for all this.
Who is online
Users browsing this forum: No registered users and 7 guests