dates in @elem

For questions regarding programming in the EViews programming language.

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

EviewsUser1
Posts: 37
Joined: Thu Aug 28, 2014 8:08 am

dates in @elem

Postby EviewsUser1 » Thu Jul 27, 2017 12:23 pm

I define the start date of the sample:

%start="1984q1"

and I want to extract a single data point for that series dat using @elem

scalar first_actual=@elem(dat,"1984q1")

but instead of using "1984q1" I would like to use %start

but that does not work. Any suggestions?

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

Re: dates in @elem

Postby EViews Gareth » Thu Jul 27, 2017 12:56 pm

Code: Select all

wfcreate q 1980 2000
series dat=nrnd
%start = "1984q1"
scalar first_actual=@elem(dat,%start)
show first_actual
Follow us on Twitter @IHSEViews

jccondi
Posts: 7
Joined: Fri Jun 01, 2018 8:02 am

Re: dates in @elem

Postby jccondi » Fri Jun 08, 2018 10:54 am

Hi,

I'm trying to do something similar. I would like to update some series to a date inputed by a program. For example, my group is like this:

serie1/@elem(serie1, %0-360)*100

Where %0 is the given date. But unfortunatelly, it doesn't work.
So, basically, what I need is to update my series taking in consideration a given period, every time I run the program. Is that possible?

EViews Matt
EViews Developer
Posts: 557
Joined: Thu Apr 25, 2013 7:48 pm

Re: dates in @elem

Postby EViews Matt » Fri Jun 08, 2018 11:39 am

Hello,

The second argument to @elem, the date, cannot be an expression of the form you've shown. You need to create the date you want before @elem.

jccondi
Posts: 7
Joined: Fri Jun 01, 2018 8:02 am

Re: dates in @elem

Postby jccondi » Fri Jun 08, 2018 12:47 pm

Thanks! How can I create such date? Is there an especial element to do it in Eviews? I've already tried scalar, but it didn't work.

EViews Matt
EViews Developer
Posts: 557
Joined: Thu Apr 25, 2013 7:48 pm

Re: dates in @elem

Postby EViews Matt » Fri Jun 08, 2018 2:30 pm

If your "dates" are just simple observation numbers, you can create the adjusted date string simply as,

Code: Select all

%tmp = @str(%0 - 360)

However, if you're dealing with formatted date strings, e.g., "1/1/1990", then @dateadd should be used to perform the adjustment. Since @dateadd operates on EViews' date numbers rather than data strings, some conversion to/from date numbers is also needed. For example,

Code: Select all

%tmp = @datestr(@dateadd(@dateval(%0), -360, "DD"))

Bjellerup
Posts: 3
Joined: Mon Dec 16, 2019 6:16 am

Re: dates in @elem

Postby Bjellerup » Mon Feb 10, 2020 7:08 am

Hi Matt,

I'm still struggling with this. I have a workfile in quarterly format. At the start of the program file I have

%sobs="1993Q1"

and then later on I have (rebasing a series)

series p1us = pceus/@elem(pceus,"%sobs")

but it doesn't work. I thought I knew what to do using @dateval and @datestr, but as it turns out, I didn't. Could please help me out?

Rgds,

Mårten

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

Re: dates in @elem

Postby EViews Gareth » Mon Feb 10, 2020 7:15 am

Remove the quotes in @elem
Follow us on Twitter @IHSEViews

Bjellerup
Posts: 3
Joined: Mon Dec 16, 2019 6:16 am

Re: dates in @elem

Postby Bjellerup » Mon Feb 10, 2020 7:24 am

Thanks! Strange, I tried that earlier and it didn't work. Must have got it wrong in some other way I guess.

Bjellerup
Posts: 3
Joined: Mon Dec 16, 2019 6:16 am

Re: dates in @elem

Postby Bjellerup » Mon Feb 10, 2020 8:34 am

Hi again,

Later in the program I'm trying to create a loop that rolls one step forward at a time. Unfortunately, I don't get the date format right.

I'm trying something like (where %sobs and %fobs are defined earlier as "1993q1" and "2008q1")

for !i=1 to !nrolls step 1
%first=%sobs
%last=%fobs+!i

I suspect I need to tranform %fobs in the last line but I don't understand how. Do I mix string and scalar here?

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

Re: dates in @elem

Postby EViews Gareth » Mon Feb 10, 2020 8:40 am

Use the @dateadd function, or a mixture of @dtoo and @otod and @dateval/@datestr to convert from string to date to observation number and back again.
Follow us on Twitter @IHSEViews

mamo
Posts: 189
Joined: Wed Nov 07, 2012 9:11 am

Re: dates in @elem

Postby mamo » Wed Feb 12, 2020 5:00 am

Depending on what you want to do with the rolling samples, you may also just enlarge the sample stepwise as follows

Code: Select all

%sobs="1993Q1"
%fobs="2008q1"
!nrolls=10

for !i=1 to !nrolls step 1
   smpl %sobs %fobs+!i
   ' do sth. here with the enlarged sample
next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 12 guests