Troubles with @datestr

For questions regarding programming in the EViews programming language.

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

thaigrrr
Posts: 9
Joined: Wed Feb 27, 2013 9:49 am

Troubles with @datestr

Postby thaigrrr » Fri Mar 01, 2013 2:37 pm

Good afternoon,

I have, what seems to be a simple issue, but may be Friday brain-block is preventing me from seeing a solution. The code

Code: Select all

%rec_end = "2012:1" ' smpl %rec_end %ols_stop !nQtr = @obssmpl for !q = 1 to !nQtr %ols_stop = @datestr(@dateval(%rec_end)+!q-1, "yyyy:q")) show %ols_stop next
fails to show the next value for %ols_stop, but if I remove ", "yyyy:q"" from it shows the new value (just not in the format that I want.)

I can't see the mistake, since the code above is adapted from another code I've written:

Code: Select all

%rec_end = "2012:1" ' %rec_start = %ols_stop smpl %rec_end %rec_start !nQtr = @obssmpl for !q = 1 to (!nQtr) %rec_start = @datestr(@dateval(%ols_stop)-!q+1, "yyyy:q") next
The second code works fine. The difference between them, in theory, is that the first one adds a quarter to each loop, while the second code subtracts from each loop.

My feeling is that the solution is very simple, but my eyes are crossed and I just can't see what's wrong.

Thank you for any suggestions/help.

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

Re: Troubles with @datestr

Postby EViews Gareth » Fri Mar 01, 2013 2:59 pm

Too many close parenthesis in the first one.

thaigrrr
Posts: 9
Joined: Wed Feb 27, 2013 9:49 am

Re: Troubles with @datestr

Postby thaigrrr » Fri Mar 01, 2013 3:15 pm

I removed the extra parenthesis, but that didn't seem to fix the issue and %ols_stop is still not being updated.

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

Re: Troubles with @datestr

Postby EViews Gareth » Fri Mar 01, 2013 3:35 pm

You're probably just not moving through any quarters. Since you're displaying the date in quarter format, it will only change once you move from one quarter to another.

thaigrrr
Posts: 9
Joined: Wed Feb 27, 2013 9:49 am

Re: Troubles with @datestr

Postby thaigrrr » Fri Mar 01, 2013 3:43 pm

The weird thing is if I include "show !q" right before the line, then I can see !q is being looped through. %ols_stop just doesn't update.

What gets me is that if I remove the format in @datestr, then the line loops fine. It boggles me why it wouldn't move through the quarter when I only revised it slightly from the original code :cry:

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

Re: Troubles with @datestr

Postby EViews Gareth » Fri Mar 01, 2013 3:52 pm

My point is that !q is looping, but just not far enough.

If the first time through the loop, you're dealing with January 1st 2012, then %ols_start will be "2012:1".
The second time through the loop, you're dealing with January 2nd 2012, then %ols_start will be "2012:1".
The third time through the loop, you're dealing with January 3rd 2012, then %ols_start will be "2012:1"

and so on...

It would take 100 (roughly) runs through the loop before the quarter changed.

thaigrrr
Posts: 9
Joined: Wed Feb 27, 2013 9:49 am

Re: Troubles with @datestr

Postby thaigrrr » Fri Mar 01, 2013 4:03 pm

Ah... I see what you mean now, but I still don't see why it works in the second code but not in the first...

Do you think the order of the variables within @datestr matters? I think when I moved them around to @dateval(%rec_end)-1+!q, I got it to loop through twice. Not exactly the final result I wanted, but an improvement of some sort.

I'll just leave this as unsolved mystery and use the second code with modifications into what I want. I really appreciate your replies on this, Gareth.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests