Page 1 of 1

Using last observation in graph text

Posted: Fri Apr 27, 2018 4:52 pm
by terrya
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.

Re: Using last observation in graph text

Posted: Mon Apr 30, 2018 4:07 pm
by EViews Jason
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?

Re: Using last observation in graph text

Posted: Mon Apr 30, 2018 5:51 pm
by terrya
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.

Re: Using last observation in graph text

Posted: Wed May 16, 2018 11:24 am
by EViews Jason
Try using the following code to get the string representation of the last year in the workfile

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

Posted: Wed May 16, 2018 2:44 pm
by terrya
Hi

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

Posted: Wed May 16, 2018 2:55 pm
by terrya
Hi

I just tried @stripquotes to see if this fixed things but it didn't, presumably because I used %last_year still.

Re: Using last observation in graph text

Posted: Wed May 16, 2018 2:58 pm
by EViews Gareth
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

Re: Using last observation in graph text

Posted: Wed May 16, 2018 4:02 pm
by terrya
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

Posted: Wed May 16, 2018 8:19 pm
by terrya
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.