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

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

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

Postby maragloria » Tue Jun 01, 2021 12:49 pm

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
Attachments
temp_A.wf1
(13.23 MiB) Downloaded 153 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Tue Jun 01, 2021 1:26 pm

Simple solution is to use @val to convert the alpha series into a numerical series prior to unstacking.
Follow us on Twitter @IHSEViews

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

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

Postby maragloria » Tue Jun 08, 2021 6:46 am

Thank you Gareth! It works.

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

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

Postby maragloria » Mon Nov 15, 2021 9:56 am

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_* *
Last edited by maragloria on Thu Nov 18, 2021 11:13 am, edited 1 time in total.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Mon Nov 15, 2021 10:42 am

You'll just have to use the commands to set them.
Follow us on Twitter @IHSEViews

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

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

Postby maragloria » Thu Nov 18, 2021 11:12 am

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
Attachments
zap_cg.zip
(3.19 MiB) Downloaded 134 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Thu Nov 18, 2021 11:31 am

I'm not sure what you're asking.
Follow us on Twitter @IHSEViews

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

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

Postby maragloria » Thu Nov 18, 2021 4:01 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Fri Nov 19, 2021 7:41 pm

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
Follow us on Twitter @IHSEViews

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

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

Postby maragloria » Mon Nov 22, 2021 10:57 am

Wow, awesome! Very handy indeed! Thanks very much for the help.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 10 guests