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!!
Command / function for max (EV 6)
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
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)
Code: Select all
scalar max = x
if y>x then
max = y
endif
Re: Command / function for max (EV 6)
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.
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)
Lots of ways to do it. You could copy my code directly in, replacing max,x,y and for your variables. Or something like:
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.
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)
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
Re: Command / function for max (EV 6)
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.
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.
Re: Command / function for max (EV 6)
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.
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.
This needs to be corrected as I am getting error message when I call it in this code:
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.
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 Code: Select all
subroutine setzero(matrix !mat)
if !mat = 'phi1000'
!mat = 0
endif
endsub 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 Re: Command / function for max (EV 6)
Please disregard my previous post. In the end, this worked:
I was not able to solve it without the help of Gareth. Many thanks!!
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 Who is online
Users browsing this forum: No registered users and 1 guest
