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

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

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

Unread post 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.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

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

Unread post by TomDoan »

They're different if you use a LABELS instruction. Otherwise, they'll be the same, so you should be fine with %L(..)
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

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

Unread post 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.
Post Reply