Using last observation in graph text

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

terrya
Posts: 107
Joined: Wed Aug 26, 2009 2:37 pm

Using last observation in graph text

Postby terrya » Fri Apr 27, 2018 4:52 pm

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.

EViews Jason
EViews Developer
Posts: 714
Joined: Tue Sep 16, 2008 3:50 pm

Re: Using last observation in graph text

Postby EViews Jason » Mon Apr 30, 2018 4:07 pm

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?

terrya
Posts: 107
Joined: Wed Aug 26, 2009 2:37 pm

Re: Using last observation in graph text

Postby terrya » Mon Apr 30, 2018 5:51 pm

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.

EViews Jason
EViews Developer
Posts: 714
Joined: Tue Sep 16, 2008 3:50 pm

Re: Using last observation in graph text

Postby EViews Jason » Wed May 16, 2018 11:24 am

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

terrya
Posts: 107
Joined: Wed Aug 26, 2009 2:37 pm

Re: Using last observation in graph text

Postby terrya » Wed May 16, 2018 2:44 pm

Hi

This works except it puts quotes about the last date, i.e., "2017" rather than 2017 making the label look a little odd.

terrya
Posts: 107
Joined: Wed Aug 26, 2009 2:37 pm

Re: Using last observation in graph text

Postby terrya » Wed May 16, 2018 2:55 pm

Hi

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

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

Re: Using last observation in graph text

Postby EViews Gareth » Wed May 16, 2018 2:58 pm

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

terrya
Posts: 107
Joined: Wed Aug 26, 2009 2:37 pm

Re: Using last observation in graph text

Postby terrya » Wed May 16, 2018 4:02 pm

Yes I copied it straight from here (using copy instruction). Will try again when I get back to the laptop.

terrya
Posts: 107
Joined: Wed Aug 26, 2009 2:37 pm

Re: Using last observation in graph text

Postby terrya » Wed May 16, 2018 8:19 pm

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.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 5 guests