Command / function for max (EV 6)

For questions regarding programming in the EViews programming language.

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

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Command / function for max (EV 6)

Postby nadja123 » Mon May 10, 2010 10:25 am

Hi,

please is there something like command or function for maximum in EViews? I mean a function that would out of e.g. 3 and -1 return 3. I hope it is. It's quite urgent. Thanks!!

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

Re: Command / function for max (EV 6)

Postby EViews Gareth » Mon May 10, 2010 10:30 am

Code: Select all

scalar max = x if y>x then max = y endif

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Command / function for max (EV 6)

Postby nadja123 » Mon May 10, 2010 10:47 am

Gareth,

do you see any prompt way how to incorporate it into the following lines? I just need the !first, !second, !third be non-negative. I thought I would use a sort of max(!first, 0) function etc, but I see no obvious way how to implement your small code into the one below.

The current code may yield negative values, which is to be avoided. Don't take it personally, but I start to be tired from programming in EViews, I gave it a go, but I see that there is a limitation on each stupid step... it takes too much time and I just need to return to the forum with every trivial code line. Really disappointed, sorry for that.

Code: Select all

for !index = 2 to 5 !first = !index - 1 !second= !index - 2 !third =!index - 3 matrix phi{!index} = phi{!first} * a1 + phi{!second} * a2 + phi{!third} * a3 next

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

Re: Command / function for max (EV 6)

Postby EViews Gareth » Mon May 10, 2010 10:59 am

Lots of ways to do it. You could copy my code directly in, replacing max,x,y and for your variables. Or something like:

Code: Select all

subroutine max(scalar !max, scalar !x, scalar !y) !max = !x if !y>!x then !max = !y endif endsub for !index = 2 to 5 !first = !index - 1 call max(!first,!first,0) !second= !index - 2 call max(!second,!second,0) !third =!index - 3 call max(!third,!third,0) matrix phi{!index} = phi{!first} * a1 + phi{!second} * a2 + phi{!third} * a3 next

No offense taken on your complaints. The EViews language can be a bit basic (ha, that's a pun - it was modeled after Basic originally!), and often requires some thinking to do something that might be simpler in other languages.

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

Re: Command / function for max (EV 6)

Postby EViews Gareth » Mon May 10, 2010 11:01 am

Actually, given your exact needs, a better way would be:

Code: Select all

subroutine max0(scalar !x) if !x<0 then !x=0 endif endsub for !index = 2 to 5 !first = !index - 1 call max0(!first) !second= !index - 2 call max0(!second) !third =!index - 3 call max0(!third) matrix phi{!index} = phi{!first} * a1 + phi{!second} * a2 + phi{!third} * a3 next

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Command / function for max (EV 6)

Postby nadja123 » Mon May 10, 2010 11:07 am

Gareth,

thanks for your suggestions. I will check them out. You are absolutely right by saying that EV simply requires more programming. I do not find myself any 'programmer' and I feel like trying to surpass own shadow... All this started because I cannot use custom identification in structural VAR... Many thanks, but I am afraid that a next problem will arise soon.

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Command / function for max (EV 6)

Postby nadja123 » Mon May 10, 2010 2:01 pm

Gareth,

the latter code you posted works just marvellous. However, the problem is in reality more tricky:
I need to avoid a negatively indexed matrix to avoid error message,
but, more importantly I need to set the matrix itself, which yields a negative index, to zero.

In the code's last equation, phi matrices on right hand side act as weights to matrices a1, a2, a3. It is actually very important to distinguish between a "naturally zero index" and a "naturally negative index": Phi0 needs to be defined as indentity matrix. By contrast, the negative indexed phi matrices need to be set to zero.

I thought I could solve the problem by creating two subroutines. The first one is a copy paste of yours, but now it would set the index to 1000 instead of zero.

Code: Select all

subroutine set1000(scalar !x) if !x<0 then !x=1000 endif endsub
A second subroutine should recognize, whether a matrix name is 'phi1000'. If yes, it would set such a matrix to zero, otherwise it would keep the matrix untouched. I never take the chain of phi-s up to more than about 30, so it would be well recognizable.

Code: Select all

subroutine setzero(matrix !mat) if !mat = 'phi1000' !mat = 0 endif endsub
This needs to be corrected as I am getting error message when I call it in this code:

Code: Select all

for !index = 2 to 5 !first = !index - 1 call set1000(!first) call setzero(phi{!first}) !second = !index - 2 call set1000(!second) call setzero(phi{!second}) !third = !index - 3 call set1000(!third) call setzero(phi{!third}) matrix phi{!index} = phi{!first} * a1 + phi{!second} * a2 + phi{!third} * a3 next
Please if possible, I woud be very thankful for feedback to this. Thanks for encouragement today, I almost gave it up. For me programming is no easy.

nadja123
Posts: 72
Joined: Thu Aug 06, 2009 10:43 am

Re: Command / function for max (EV 6)

Postby nadja123 » Tue May 11, 2010 2:36 am

Please disregard my previous post. In the end, this worked:

Code: Select all

subroutine set1000(scalar !x) if !x<0 then !x = 1000 endif endsub

Code: Select all

'create in the workfile matrix phi1000 with appropriate dimensions and zeros everywhere: for !index = 2 to 5 !first = !index - 1 call set1000(!first) !second= !index - 2 call set1000(!second) !third =!index - 3 call set1000(!third) matrix phi{!index} = phi{!first} * a1 + phi{!second} * a2 + phi{!third} * a3 next
I was not able to solve it without the help of Gareth. Many thanks!!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests