MTOS

For questions regarding programming in the EViews programming language.

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

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

MTOS

Postby dhityayl » Tue Oct 02, 2018 8:00 am

Hi.
I have a loop rolling regression programming using window 60 and step 1. The result is in matrix, and i need the result in series. First the matrix is (5,132), but i transpose it to (132,5). I wonder if i can change the matrix to series in eviews using MTOS. I've tried using the programming below, but when i run the program, it say Error in Sample: Illegal date S1 in "SMPL S1 @FIRST+59 @LAST", or "error the sample is not define in MTOS" or r1(my matrix) is not the same length with MTOS. I think i have a problem in defining the sample because the first observation length decrease from 192 to 132 when i used rolling regression with window 60.
Does anyone know how to change my matrix into series, so i have 5 series contain of 132 coloumn?
Thanks before.

Code: Select all

cd "c:\Users\Dhitya\Desktop\Program\dataset"
%filenames = @wdir("c:\Users\Dhitya\Desktop\Program\dataset")
for !k=1 to @wcount(%filenames)
   %file = @word(%filenames, !k)
   wfopen %file
   import c:\Users\Dhitya\Desktop\Program\dataset\index\Indeks_2002.csv
   import c:\Users\Dhitya\Desktop\Program\dataset\index\FF3_2002.csv
   !window = 60
   !step = 1
   !length = @obsrange
   equation eq1
   !nrolls = @round((!length-!window)/!step)
   matrix(5,!nrolls) coefmat!k
   !j=0
      for !i = 1 to !length-!window+1-!step step !step
      !j=!j+1
      smpl @first+!i-1 @first+!i+!window-2
      genr return=(((close-close(-1))/close(-1))*100)-rf
      equation eq1.ls return c indeks mkt_rf smb hml
      colplace(coefmat!k, eq1.@coefs,!j)
      matrix(!nrolls,5) r1
      matrix r1=@transpose (coefmat!k)

series col1
series col2
series col3
series col4
series col5
group g1 col1 col2 col3 col4 col5
smpl s1 @first+59 @last
mtos(r1, g1, s1)
next
next

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

Re: MTOS

Postby EViews Gareth » Tue Oct 02, 2018 9:15 am

Change smpl to sample
Follow us on Twitter @IHSEViews

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

Re: MTOS

Postby EViews Matt » Tue Oct 02, 2018 9:21 am

And your calculation of !nrolls is off by one (it should be one larger).

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Tue Oct 02, 2018 4:32 pm

Garreth, I’ve already tried to change smpl to sample, and the error message said that R1 is not the same length as MTOS.
Sorry Matt, i don’t quite understand, my calculation of !nrolls is off by one? What should the calculation be? Did i simply add +1 in the calculation?

Code: Select all

cd "c:\Users\Dhitya\Desktop\Program\dataset"
%filenames = @wdir("c:\Users\Dhitya\Desktop\Program\dataset")
for !k=1 to @wcount(%filenames)
   %file = @word(%filenames, !k)
   wfopen %file
   import c:\Users\Dhitya\Desktop\Program\dataset\index\Indeks_2002.csv
   import c:\Users\Dhitya\Desktop\Program\dataset\index\FF3_2002.csv
   !window = 60
   !step = 1
   !length = @obsrange
   equation eq1
   !nrolls = @round((!length-!window)+1/!step)
   matrix(5,!nrolls) coefmat!k
   !j=0
      for !i = 1 to !length-!window+1-!step step !step
      !j=!j+1
      smpl @first+!i-1 @first+!i+!window-2
      genr return=(((close-close(-1))/close(-1))*100)-rf
      equation eq1.ls return c indeks mkt_rf smb hml
      colplace(coefmat!k, eq1.@coefs,!j)
      matrix(!nrolls,5) r1
      matrix r1=@transpose (coefmat!k)
series col1
series col2
series col3
series col4
series col5
group g1 col1 col2 col3 col4 col5
sample s1 @first+59 @last
mtos(r1, g1, s1)

next
next


if i simply add +1 to nrolls calculation, the error message is S1 already exist in ‘SAMPLE S1 @first+59 @last’
Thankyou

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

Re: MTOS

Postby EViews Matt » Tue Oct 02, 2018 5:13 pm

Assuming that !step = 1, then the number of times you'll apply your rolling regression (the innermost for loop) is !length - !window + 1, not !length - !window. As is, !nrolls is one less than it should be, which causes coefmat!k to have one too few columns, which causes r1 to have one too few rows, which results in the length of r1 not matching the sample s1 (the error reported by EViews).

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Tue Oct 02, 2018 6:05 pm

Hi Matt
I’ve tried to change the !nrolls to !nrolls=!length-!window +1/!step, but it stil didnt work. The error message is S1 already exist in ‘SAMPLE S1 @first+59 @last’
Thankyou

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

Re: MTOS

Postby EViews Matt » Tue Oct 02, 2018 6:06 pm

The error about S1 already existing occurs because after the first iteration through the loop, the sample object S1 already exists. Thankfully, that sample isn't dependent on any of the work within your innermost loop (it's the same for all iterations), therefore you can move its definition before the loop.

You can also use the following to delete that sample object if it exists:

Code: Select all

if @isobject("S1") then
   delete S1
endif

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Tue Oct 02, 2018 6:36 pm

Thanks Matt, it works well.
And i have one more question. After change the matrix to series, i want each file i loop to be save in excel file. Could eviews programm automatically export just the series i want on each file to excel? What syntax should i use? I’ve tried write and wfsave before but i dont understand how can i save just the series i want.
Thanks so much for the help.

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

Re: MTOS

Postby EViews Matt » Wed Oct 03, 2018 9:01 am

I believe the @keep specification to wfsave is what you're after. For example,

Code: Select all

wfsave(type=excelxml) "test.xlsx" @keep g1

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Wed Oct 03, 2018 7:04 pm

Hi Matt,
I've tried the @keep, and it doesn't work. If i add the wfsave and @keep in my programming below, the error message said that "WSAFE is not defined or is an illegal command in "WSAFE(TYPE=EXCELXML) "C:\USERS\DHITYA\DESKTOP\TEST" @KEEP G1". Should I insert the filename in the "C:\USERS\DHITYA\DESKTOP\TEST"? Can i save the excel form eviews, using the same name as the eviews workfile by using %filenames the same way with wfopen?
Thanks!


Code: Select all

cd "c:\Users\Dhitya\Desktop\Program\dataset"
%filenames = @wdir("c:\Users\Dhitya\Desktop\Program\dataset")
for !k=1 to @wcount(%filenames)
   %file = @word(%filenames, !k)
   wfopen %file
   import c:\Users\Dhitya\Desktop\Program\dataset\index\Indeks_2002.csv
   import c:\Users\Dhitya\Desktop\Program\dataset\index\FF3_2002.csv
   genr return=(((close-close(-1))/close(-1))*100)-rf   
!window = 60
   !step = 1
   !length = @obsrange
   equation eq1
   !nrolls = @round((!length-!window+1)/!step)
   matrix(5,!nrolls) coefmat!k
   !j=0
      for !i = 1 to !length-!window+1-!step step !step
      !j=!j+1
      smpl @first+!i-1 @first+!i+!window-2
      equation eq1.ls return c indeks mkt_rf smb hml
      colplace(coefmat!k, eq1.@coefs,!j)
      matrix(!nrolls,5) r1
      matrix r1=@transpose (coefmat!k)
         series bc
         series bindeks
         series bmkt
         series bsmb
         series bhml
         group g1 bc bindeks bmkt bsmb bhml
         sample s1 @first+59 @last
         mtos(r1, g1, s1)
            if @isobject("s1") then
            delete s1
            endif

wsafe(type=excelxml) "C:\Users\Dhitya\Desktop\test" @keep g1

next
next

startz
Non-normality and collinearity are NOT problems!
Posts: 3379
Joined: Wed Sep 17, 2008 2:25 pm

Re: MTOS

Postby startz » Wed Oct 03, 2018 7:41 pm

wsave, not wsafe

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Wed Oct 03, 2018 9:13 pm

Ow okay I’ll try it again later.
Thankyou so much

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Thu Oct 04, 2018 3:22 am

Hi.
So i still haven't figure out how to save using wfsave. I have already tried the programming below, and it seems that the loop isn't working for saving the file. If i run the program below, it's just the last workfile that saved. Does anyone know which part is wrong?
Also can i save the workfile automatically using the original workfile name, i just want it to be saved to excel, with the same filename with the eviews workfile. What should I add to the programming?

Code: Select all

cd "c:\Users\Dhitya\Desktop\Program\dataset"
%filenames = @wdir("c:\Users\Dhitya\Desktop\Program\dataset")
for !k=1 to @wcount(%filenames)
   %file = @word(%filenames, !k)
   wfopen %file
   import c:\Users\Dhitya\Desktop\Program\dataset\index\Indeks_2002.csv
   import c:\Users\Dhitya\Desktop\Program\dataset\index\FF3_2002.csv
   genr return=(((close-close(-1))/close(-1))*100)-rf   
!window = 60
   !step = 1
   !length = @obsrange
   equation eq1
   !nrolls = @round((!length-!window+1)/!step)
   matrix(5,!nrolls) coefmat!k
   !j=0
      for !i = 1 to !length-!window+1-!step step !step
      !j=!j+1
      smpl @first+!i-1 @first+!i+!window-2
      equation eq1.ls return c indeks mkt_rf smb hml
      colplace(coefmat!k, eq1.@coefs,!j)
      matrix(!nrolls,5) r1
      matrix r1=@transpose (coefmat!k)
         series rbc
         series rbindeks
         series rbmkt
         series rbsmb
         series rbhml
         group g1 rbc rbindeks rbmkt rbsmb rbhml
         sample s1 @first+59 @last
         mtos(r1, g1, s1)
            if @isobject("s1") then
            delete s1
            endif
wfsave (type=excelxml) "C:\Users\Dhitya\Desktop\test" @keep date return g1
   'close @all
next
next


Thanks

EViews Steve
EViews Developer
Posts: 530
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: MTOS

Postby EViews Steve » Thu Oct 04, 2018 6:10 am

I don't see a filename specified in the WFSAVE call. I believe you always need a filename specified. Just use your %file variable.

dhityayl
Posts: 14
Joined: Sun Aug 26, 2018 10:29 pm

Re: MTOS

Postby dhityayl » Thu Oct 04, 2018 6:34 am

Hi Steve
I've tried to add %file to my program below but it doesn't work. The error message is "Path in 'C:\Users\Dhitya\Desktop\test\%file.xlsx' does not exist in "WFSAVE(TYPE=EXCELXML) "C:\USERS\DHITYA\DESKTOP\TEST\%FILE" @KEEP DATE RETURN G1".

Code: Select all

cd "c:\Users\Dhitya\Desktop\Program\dataset"
%filenames = @wdir("c:\Users\Dhitya\Desktop\Program\dataset")
for !k=1 to @wcount(%filenames)
   %file = @word(%filenames, !k)
   wfopen %file
   import c:\Users\Dhitya\Desktop\Program\dataset\index\Indeks_2002.csv
   import c:\Users\Dhitya\Desktop\Program\dataset\index\FF3_2002.csv
   genr return=(((close-close(-1))/close(-1))*100)-rf   
!window = 60
   !step = 1
   !length = @obsrange
   equation eq1
   !nrolls = @round((!length-!window+1)/!step)
   matrix(5,!nrolls) coefmat!k
   !j=0
      for !i = 1 to !length-!window+1-!step step !step
      !j=!j+1
      smpl @first+!i-1 @first+!i+!window-2
      equation eq1.ls return c indeks mkt_rf smb hml
      colplace(coefmat!k, eq1.@coefs,!j)
      matrix(!nrolls,5) r1
      matrix r1=@transpose (coefmat!k)
         series rbc
         series rbindeks
         series rbmkt
         series rbsmb
         series rbhml
         group g1 rbc rbindeks rbmkt rbsmb rbhml
         sample s1 @first+59 @last
         mtos(r1, g1, s1)
            if @isobject("s1") then
            delete s1
            endif
wfsave(type=excelxml) "C:\Users\Dhitya\Desktop\test\%file" @keep date return g1
   'close @all

next
next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 11 guests