Page 1 of 1

Function to get the name (not label) of a series as a str?

Posted: Wed Sep 02, 2015 2:42 pm
by macro
Is there a function that, given a series, returns the name of the series as a string? I can write

Code: Select all

compute [string] series_label = %l(gdp)
to get the label of the series, but given a series, is there a function that will return its name as a string? For example,

Code: Select all

dofor s = gdp cons gce gov
    compute [string] series_name = FUNCTION(s)
    display series_name
end dofor s
would display

Code: Select all

gdp
cons
gce
gov
regardless of what the series are labeled. This post https://estima.com/forum/viewtopic.php? ... ries#p4936 mentions that there is a difference between series names and series labels, but I'm not sure how to get the former into a string variable.

Re: Function to get the name (not label) of a series as a st

Posted: Wed Sep 02, 2015 4:01 pm
by TomDoan
They're different if you use a LABELS instruction. Otherwise, they'll be the same, so you should be fine with %L(..)

Re: Function to get the name (not label) of a series as a st

Posted: Wed Sep 02, 2015 4:11 pm
by macro
In my case, I have used the LABELS instruction, so the series label and the series name are different. This is related to this post (https://estima.com/forum/viewtopic.php?f=13&t=2446), where I create a placeholder series called gdp_ that contains a different transformation of GDP, depending on the model. I use LABELS because I want to display the name of the transformed series in LINREG output (for example), but I want to get the name of the placeholder series (gdp_) as a string so I can write my code to refer to my_hash("gdp_") (for example) and keep my code as general as possible.