Page 1 of 1

wfopen(type=odbc): data being unstacked as string

Posted: Tue Jun 01, 2021 12:49 pm
by maragloria
Hello,

I'm trying to unstack a dataset from SQL, but the data remains a string (instead of a "time series") when I use the unstack command. Could you please take a look on my code?

I've attached the workfile and the code follows here:

Code: Select all

wfopen(type=odbc, timeout=400, wf=temp) zap_beta {%QUERY} @id serie_name @date(start_date) @destid serie_name @date @smpl @all
pageunstack(page=Unstackt,namepat =*_?) serie_name start_date @ datavalue_converted


Many thanks,

Mara

Re: wfopen(type=odbc): data being unstacked as string

Posted: Tue Jun 01, 2021 1:26 pm
by EViews Gareth
Simple solution is to use @val to convert the alpha series into a numerical series prior to unstacking.

Re: wfopen(type=odbc): data being unstacked as string

Posted: Tue Jun 08, 2021 6:46 am
by maragloria
Thank you Gareth! It works.

Re: wfopen(type=odbc): data being unstacked as string

Posted: Mon Nov 15, 2021 9:56 am
by maragloria
Hello Gareth,

I got a follow-up question: how can I add metadata to the series' fields "display name" and "description" when the data is unstacked? The metadata are available in the workfile as string (stacked).

Please find the code I'm working with below.

Many thanks,

Mara

Code: Select all

%QUERY = " SELECT * FROM [ZAP_CG].[ollim].[haver_series_traitées] where frequency='"Q"' order by [serie_name], start_date"

wfopen(type=odbc, timeout=400) zap_cg {%QUERY} @id serie_name @date(start_date) @destid serie_name @date @smpl @all
series datavalue = @val(datavalue_converted) 'convert alpha series into time series
pageunstack(page="Q",namepat =*_?) serie_name start_date @ datavalue
pagestruct(bal=se) @date(start_date)
rename datavalue_* *

Re: wfopen(type=odbc): data being unstacked as string

Posted: Mon Nov 15, 2021 10:42 am
by EViews Gareth
You'll just have to use the commands to set them.

Re: wfopen(type=odbc): data being unstacked as string

Posted: Thu Nov 18, 2021 11:12 am
by maragloria
Hello Gareth,

Thanks for your reply. I'm a bit loss on how to use setattr on stacked data. Could you take a look at my file and tell me how for instance to add the alpha values "target_desc" to the attribute "display name" for each country series?

The series id are in "serie_name" and the data in "datavalue".

Many thanks,

Mara

Re: wfopen(type=odbc): data being unstacked as string

Posted: Thu Nov 18, 2021 11:31 am
by EViews Gareth
I'm not sure what you're asking.

Re: wfopen(type=odbc): data being unstacked as string

Posted: Thu Nov 18, 2021 4:01 pm
by maragloria
Hello Gareth,

I'll try to make it more clear.

In the page Zap_cg I got stacked qtly data in "datavalue".
I'm unstacking into a new q page (not shown in the file I've sent), using "serie_name" as the id:
pageunstack(page=q,namepat =*_?) serie_name start_date @ datavalue

In the page Zap_cg, there're also a few alpha objects storing some metadata. I would like to add some of these metadata as attributes to the unstacked time series in the new page q.

So, for instance, the first line in the stacked "datavalue" is BIS_CRDGGOV_ARG - 92Q4. This turns into a time series called BIS_CRDGGOV_ARG running from 92Q4 to 21Q1 when unstacked. I would like to add "Argentina: Adjusted Credit to the General Government [Nom Val] (EOP, % of GDP)" found in the alpha object haver_desc as the attribute Description to BIS_CRDGGOV_ARG (the resulting unstacked time series in the new page q). I couldn't manage to do it.

Re: wfopen(type=odbc): data being unstacked as string

Posted: Fri Nov 19, 2021 7:41 pm
by EViews Gareth
Ah, for that you can use the handy importattr command.

Code: Select all

pageunstack(page=q,namepat =*_?) serie_name start_date @ datavalue

d datavalue
rename datavalue_* *

importattr(name=serie_name) zap_cg @keep haver_desc
%serlist = @wlookup("*", "series")
for %j {%serlist}
   %newdesc = {%j}.@attr("haver_desc")
   {%j}.setattr("Description") {%newdesc}
next

Re: wfopen(type=odbc): data being unstacked as string

Posted: Mon Nov 22, 2021 10:57 am
by maragloria
Wow, awesome! Very handy indeed! Thanks very much for the help.