On Mon, 4 Jan 2021, Riccardo (Jack) Lucchetti wrote:
On Mon, 4 Jan 2021, Allin Cottrell wrote:
> On Mon, 4 Jan 2021, Sven Schreiber wrote:
>
>> Am 04.01.2021 um 09:47 schrieb Artur Bala:
>>>> Use the argname() function.
>>>>
>>>> Allin
>>>
>>> Yeah, that's quite clear but argname() generates a string not a
>>> series. And my point is different. Let's have the following:
>>> <\hans>
>>> function matrix myfunction (series depY, list X)
>>> # some coding
>>> ols depY X
>>> # some coding
>>> return something
>>> end function
>>> <hans>
>>>
>>> Now, when I run my function, let's say "mymatrix =
myfunction(Price,
>>> xlist)", OLS printing will show up: "Dependent variable: depY"
instead
>>> of "Dependent variable: Price".
>>> Is there a way to have the actual name of depY displayed?
>>
>> You could copy the input using argname, for example:
>> ID = genseries(argname(depY), depY)
>>
>> Then you should be able to use the ID number also in the OLS command.
>> Of course the copying doesn't make it 100% efficient, but the loss
>> should be minor.
>
> Or if you don't mind using string substitution, you could use
"rename":
>
> <hansl>
> function matrix myfunction (series depY, list X)
> string realname = argname(depY)
> rename depY @realname
> ols @realname X
> ...
> end function
> </hansl>
The problem with these approaches is that what you pass to the function may
not be a valid identifier, for example
myfunction(log(y), X)
and anything based on argname would break down in that case.
Good point, but the optional argument to argname can be used to
prevent breakage:
string realname = argname(depY, "depY")
If what you want is be sure that what your function prints makes
sense I would suggest to fine-tune the printout using tools like
printf, sprintf() and modprint, which give you complete control on
what to print and how. [...]
Agreed, that's the clean solution.
Allin