Page 1 of 1

Get variable names and values as strings

Posted: Tue Nov 17, 2015 5:57 am
by tho_mi
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!

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 7:21 am
by EViews Gareth
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.

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 8:12 am
by tho_mi
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?

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 8:59 am
by EViews Gareth

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

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 9:19 am
by tho_mi
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).

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 10:26 am
by EViews Gareth
Using + works.

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 10:37 am
by tho_mi
Using + works.
Not really?

Code: Select all

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

Code: Select all

"loggdp" + "test"

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 10:42 am
by EViews Gareth

Code: Select all

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

Re: Get variable names and values as strings

Posted: Tue Nov 17, 2015 11:11 am
by tho_mi

Code: Select all

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