FLIPTYPE

For technical support, tips and tricks, suggestions, or any other information regarding the EViews model object.

Moderators: EViews Gareth, EViews Moderator

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

FLIPTYPE

Postby tvonbrasch » Sat Dec 25, 2021 7:22 am

Hi,

Is there a way of fetching the variables that have been made exogenous when using the FLIPTYPE command?

It would be great if you could add a string function to retrieve that info. For now, I have been trying to make a program that retrieves this information from the msg-window after having used the FLIPTYPE command. However, the strings and information in this msg-window have been cut (with the last part being "..."), so that all information is not readily available here:

2021-12-25 14_01_55-EViews.png
2021-12-25 14_01_55-EViews.png (12.92 KiB) Viewed 21520 times


I have tried to make a program that uses the information in the msg-window to identify which variables have been made exogenous, but it is not perfect ... (see below)

Questions:

a) how can one use the msg-window to identify which variables have been made exogenous? (is there some way I can change the program below to accomplish this?)

b) could you please add a command that creates a string that holds the variables that have been made exogenous when using the FLIPTYPE command?

Thomas


Code: Select all

'store fliptypemessage
   freeze({%maux}_info) {%maux}.msg

   'find variables that are made exogenous, have to loop across the entire fliptype msg window
   !lines={%maux}_info.@linecount
   !iterline=0
   for !i = 1 to !lines
      %wordtotal=""
      %wordtotals =""
      %exogline= {%maux}_info.@line(!i)
         !test= @instr(%exogline, "Equation ")

         if !test>0 then
            if %exogline<>"Equation Details" then
             !iterline=!iterline+1
            'must change the %exogline string since the equation is cut in EViews. But all we need is the info before the equality sign. As long as the equality sign is early in the equation, this approach should be fine (but it would be better if EViews could just provide us with this info)
               %exogline= @mid( %exogline, 9) '@wnotin(@upper(%exogline), @upper("Equation ")) 'left with only equation
               !testequality= @instr(%exogline, "=")-1

            if  !testequality>0 then

               %exogline =@left(%exogline,    !testequality)

               else

               'if the equality sign was not present in the string, we try to use the first couple of words
                  !lentest=0
                  !iterw=0
                  while !lentest<70
                     !iterw=!iterw+1
                     %word=@word(%exogline,!iterw)

                     %wordtotals=%wordtotal
                     %wordtotal=%wordtotal+" " + %word
                     !lentest=@len(%wordtotal)


                     'do not need to continue if first operator is division
                     if @trim(%word)="/"  then
                        %wordtotal=%wordtotals 'do not add last word
                        !lentest=1000                            
                     endif

                     'do not need to continue loop if we have 8 words of the equations
                     if !iterw=8 then
                        !lentest=1000

                        'do not add the last word if it is an operator
                        if @trim(%word)="+" or @trim(%word)="-" or @trim(%word)="*"  or @trim(%word)="/"  then
                           %wordtotal=%wordtotals 'do not add last word
                        endif
                     endif
               wend

               %exogline = %wordtotal

            endif

            'add equality sign and zero to make the equation complete
            %exogline = %exogline + "=0"

            'find the left hand side variable of the equation that has been changed
               %modellineaux=@getnextname("zaux")
               model {%modellineaux}
                {%modellineaux}.append {%exogline}
               %exogvarmodellineaux={%modellineaux}.@endoglist
               delete {%modellineaux}

            'make list of dropped exogenous variables
               %droppedexog= %droppedexog + " " + %exogvarmodellineaux

            endif
         endif
   next
   %droppedexog=@wsort(%droppedexog)

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

Re: FLIPTYPE

Postby EViews Matt » Wed Dec 29, 2021 6:55 pm

Hello,

In light of the limitations of the summary table, until such time as new convenience data members may be added I believe the easiest approach will be to utilize the existing data members for endogenous/exogenous/add-factor information to deduce the changes. Allow me to demonstrate:

Code: Select all

logmode l
create u 1
' Create a trivial model with 50 equations.
model m
for !i = 1 to 50
   m.append x!i = y!i
next
m.addassign @all
' We're going to flip the first 25 equations.
for !i = 1 to 25
   %tmp = %tmp + @wcross("x y", @str(!i)) + " "
next

%preendog = m.@endoglist
%preexog = m.@exoglist
%preaddin = m.@addfactors
m.fliptype {%tmp}
%postendog = m.@endoglist
%postexog = m.@exoglist
%postaddin = m.@addfactors
%flippedtoendog = @wnotin(%postendog, %preendog)
%flippedtoexog = @wnotin(%postexog, %preexog)
%droppedaddin = @wnotin(%preaddin, %postaddin)
m.msg
logmsg Made Endogenous: {%flippedtoendog}
logmsg Made Exogenous: {%flippedtoexog}
logmsg Dropped add factors: {%droppedaddin}

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

Re: FLIPTYPE

Postby tvonbrasch » Thu Dec 30, 2021 4:05 am

Hi Matt,

This is great, thanks!

Another quick question: I am looking for a string of all endogenous variables which equation has been changed using the fliptype command. Consider the example:
2021-12-30 12_00_40-EViews.png
2021-12-30 12_00_40-EViews.png (23.41 KiB) Viewed 21396 times


I am looking for the string: "CP66 CP64 C66 CW64". Is there a clever way of retrieving this string from the fliptype msg window?

Thanks again for looking at this!
Thomas

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

Re: FLIPTYPE

Postby EViews Matt » Tue Jan 04, 2022 3:12 pm

Another good candidate for a new data member. Otherwise, a brief loop can extract the information...

Code: Select all

logmode l
create u 1
' Create a trivial model with 50 equations.
model m
for !i = 1 to 50
   m.append x!i = y!i
next
m.addassign @all
' We're going to flip the first 25 equations.
for !i = 1 to 25
   %tmp = %tmp + @wcross("x y", @str(!i)) + " "
next

m.fliptype {%tmp}
m.msg
freeze(info) m.msg
for !row = 2 to info.@linecount
   if @word(info.@line(!row), 1) = "Rewritten" then
      %modified = %modified + @word(info.@line(!row - 1), 2) + " "
   endif
next
logmsg {%modified}

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

Re: FLIPTYPE

Postby tvonbrasch » Wed Jan 05, 2022 1:10 am

Great, thanks for your feedback, Matt.

However, the code is not robust to other equation specifications. For example consider the specification:

Code: Select all

D(x!i , 0 , 4)  -  y!i+0.0101545333066 + C__2K6000 * (LOG(PC00 / PC66) - LOG(PC00(-4) / PC66(-4))) + C__2K6003 * (LOG(PC02 / PC66) - LOG(PC02(-4) / PC66(-4))) + C__2K60CU * (LOG(PCCU / PC66) - LOG(PCCU(-4) / PC66(-4))) + C__2K6014 * (LOG(PC14 / PC66) - LOG(PC14(-4) / PC66(-4))) + C__2K6020 * (LOG(PC22 / PC66) - LOG(PC22(-4) / PC66(-4))) =0


In this case, the equation string is cut from the message window, and the variable we are interested in is not the second word on that line. I have used your example to illustrate (see also code below):
2022-01-05 09_14_18-EViews.png
2022-01-05 09_14_18-EViews.png (25.53 KiB) Viewed 21254 times


In my first post, my idea was to take this string and make an auxiliary model object of it, and then fetch the endogenous variable of that auxiliary model. However, when the string is cut, it is not trivial to find a part of the string that can be made to an auxiliary model in a meaningful way. I thought of using the equality sign, but the equality sign might appear after the string is cut, as in the example below ...

Do you have a clever way of getting around this problem?
Thomas

Code: Select all


logmode l
create u 1
' Create a trivial model with 50 equations.
model m
for !i = 1 to 50
   m.append D(x!i , 0 , 4)  -  y!i+0.0101545333066 + C__2K6000 * (LOG(PC00 / PC66) - LOG(PC00(-4) / PC66(-4))) + C__2K6003 * (LOG(PC02 / PC66) - LOG(PC02(-4) / PC66(-4))) + C__2K60CU * (LOG(PCCU / PC66) - LOG(PCCU(-4) / PC66(-4))) + C__2K6014 * (LOG(PC14 / PC66) - LOG(PC14(-4) / PC66(-4))) + C__2K6020 * (LOG(PC22 / PC66) - LOG(PC22(-4) / PC66(-4))) =0
next

m.addassign @all
' We're going to flip the first 25 equations.
for !i = 1 to 25
   %tmp = %tmp + @wcross("x y", @str(!i)) + " "
next

m.fliptype {%tmp}
m.msg
freeze(info) m.msg
for !row = 2 to info.@linecount
   if @word(info.@line(!row), 1) = "Rewritten" then
      %modified = %modified + @word(info.@line(!row - 1), 2) + " "
   endif
next
logmsg {%modified}

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

Re: FLIPTYPE

Postby EViews Matt » Wed Jan 05, 2022 10:37 am

I knew you'd ask that. :lol: In which case, to avoid parsing each specification for the first variable name perhaps it's best to include an add factor on all equations, thus the set of dropped add factors will match the set of modified equations.

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

Re: FLIPTYPE

Postby tvonbrasch » Thu Jan 06, 2022 1:47 am

Hi Matt,

Thanks again for your response :-).

However, the problem with that approach is that the string in the msg window with the dropped add factor series is cut:
2022-01-05 09_14_18-EViews.png
2022-01-05 09_14_18-EViews.png (25.53 KiB) Viewed 21204 times


All the dropped add factor series can thus not be fetched from the msg window. I encountered this problem with our model, so this is actually what led me to go through all the rewritten equations. But the way I am doing it is not perfect and will lead to an error at some point ... Do you have a bulletproof way of parsing these equation strings so that we are left with a string of all endogenous variables which equation has been changed?

Thomas

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

Re: FLIPTYPE

Postby EViews Matt » Thu Jan 06, 2022 8:45 am

Hello,

Using the message window, the parsing loop of two posts back could be modified to look for the individual "Dropped add factor series " lines and extract them all that way.

tvonbrasch
Posts: 540
Joined: Fri Apr 15, 2011 5:35 am

Re: FLIPTYPE

Postby tvonbrasch » Fri Jan 07, 2022 12:03 pm

embarrassing :lol:

thanks!
t


Return to “Models”

Who is online

Users browsing this forum: No registered users and 20 guests