I have a code for loop programming below. So basically i loop a rolling regression and after that i want to save to excel.
The code below works for the looping itself (without wfsave), but in the middle of the looping with wfsave, the loop failed. The error message is : File IO failed for file 'Could not create entry in zip file.' in "WFSAVE(TYPE=EXCELXML) "C:\USERS\DHITYA\DESKTOP\2\2001.T.CSV.XLSX" @KEEP DATE RETURN G1".
Is there something wrong with the code? It works before with just 2 files, but when i do 50 files, it failed.
If i want to try running the program again with different data, i should create a new destination folder to save my file, but it will failed again in the middle of the loop.
Thankyou
Code: Select all
cd "D:\Thesis_Loop\2002_2\dataset"
%filenames = @wdir("D:\Thesis_Loop\2002_2\dataset")
for !k=1 to @wcount(%filenames)
%file = @word(%filenames, !k)
wfopen %file
import D:\Thesis_Loop\2002_2\dataset\index\Indeks_2002.csv
import D:\Thesis_Loop\2002_2\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
%path = "C:\Users\Dhitya\Desktop\2\" + %file + ".xlsx"
wfsave(type=excelxml) %path @keep date return g1
'close @all
next
next