Get variable names and values as strings

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Get variable names and values as strings

Postby tho_mi » Tue Nov 17, 2015 5:57 am

Hey,

I'm doing calculations with different series and different "settings". I'd like to put the information about the series and the settings in the title of the graph. I know how to change the title, but I don't know how to:

1. Get the variable names/values as strings, and
2. concatenate them to a title.

My code looks like the following:

Code: Select all

!quarters = 3 !threshold = 0.01 series finseries = loggdp graph gr1 finseries gr1.addtext(t) graphtitle
where the title should look like the following:
"Series = loggdp, quarters = 3, threshold = 0.01%"

Thanks in advance!

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

Re: Get variable names and values as strings

Postby EViews Gareth » Tue Nov 17, 2015 7:21 am

I'm not quite sure what you're asking here.

To retrieve the name of a series (or any object), you can use objectname.@name. But that's generally silly since you need to use the name of the object.

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Get variable names and values as strings

Postby tho_mi » Tue Nov 17, 2015 8:12 am

I think it would be easiest if I would be able to access a series with its name as string.

E.g.:

Code: Select all

!seriesname = "loggdp" !quarters = 3 !threshold = 0.01 series finseries = *get_series_from_!seriesname* graph gr1 finseries gr1.addtext(t) graphtitle
Is there any possibility to do this?

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

Re: Get variable names and values as strings

Postby EViews Gareth » Tue Nov 17, 2015 8:59 am

Code: Select all

%seriesname = "loggdp" !quarters = 3 !threshold = 0.01 series finseries = {%seriesname} graph gr1 finseries gr1.addtext(t) graphtitle
Although in that particular case you'd be better off just doing:

Code: Select all

%seriesname = "loggdp" !quarters = 3 !threshold = 0.01 graph gr1 {%seriesname} gr1.addtext(t) graphtitle

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Get variable names and values as strings

Postby tho_mi » Tue Nov 17, 2015 9:19 am

Strange, I tried something similar before (which I also found here), but that didn't work. Whatever, this works now, thanks!

Two more questions:
1. How do I concatenate strings? Using just a "+" leads to

Code: Select all

"loggdp" + string1
%seriesname alone as title works fine, there are no quotation marks, but "adding" another string with a "+" leads to quotation marks around the seriesname, which I don't want.

edit:
I use "finseries" for some calculations afterwards, hence I use it as additional variable (this makes it easier to replace it by another series).

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

Re: Get variable names and values as strings

Postby EViews Gareth » Tue Nov 17, 2015 10:26 am

Using + works.

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Get variable names and values as strings

Postby tho_mi » Tue Nov 17, 2015 10:37 am

Using + works.
Not really?

Code: Select all

gr1.addtext(t) %seriesname + "test"
gives

Code: Select all

"loggdp" + "test"

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

Re: Get variable names and values as strings

Postby EViews Gareth » Tue Nov 17, 2015 10:42 am

Code: Select all

%mytitle = %seriesname + "test" gr1.addtext(t) {%mytitle}

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Get variable names and values as strings

Postby tho_mi » Tue Nov 17, 2015 11:11 am

Code: Select all

%mytitle = %seriesname + "test" gr1.addtext(t) {%mytitle}
Perfect, thanks a lot!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests