error G0534 : Cannot create file

Hi, I am trying to run a code from a journal article (available from: http://www.ssc.wisc.edu/~bhansen/progs/factor.html) to recreate the results.

When I run factor_modavg_samplesplit_crossval_1.gss file, I change the filepaths in lines 27-29 and 51-54, but get the following error message:

G0534 : Cannot create file C:\Users\zelda.fmt 'C:\Users\zelda.fmt' [factor_modavg_samplesplit_crossval_1.gss, line 380]

Please can you explain what I'm doing wrong?

Many thanks.

9 Answers



1



That error means that the user account that is running GAUSS does not have write permissions in that directory. You will need to have the file created in another folder on your computer.

If you have any questions about how to do that, please ask!



1



This error is probably happening because you do not have Excel installed on your computer. The standard method that GAUSS for Windows uses to read and write Excel files requires Excel to be installed on your computer.

If you have GAUSS 13 or later, there is also another method available that does NOT require Excel to be installed. On Linux and Mac, this is the default. To turn this on for Windows, you will need to edit your xls.src file. You can open this file by entering:

edit xls.src

from the GAUSS command line. Around lines 38-40, you should see this code:

#ifOS2WIN
   #define USECOMEXCEL 1
#endif

You need to comment all out all three of these lines. When you have done this, they should look like this:

//#ifOS2WIN
//   #define USECOMEXCEL 1
//#endif

Now that this is done, you should run the xls.src file so that GAUSS has the updated definitions. You can do this by entering:

run xls.src

from the GAUSS command line.

aptech

1,773


1



It is possible that the file is in a very old Excel file format. The GAUSS library that does not call Excel, but reads and writes the files directly cannot read files in formats older than the Excel 97-2003 format. That is a possibility, but would be a little surprising. If this is the case, you can open the file with Excel and then save it as a newer format Excel file. This should solve your problem. However, it is worth trying one more thing to make sure that you are not making another mistake.

Verify that reading/writing of Excel files is working
To find out if your GAUSS set up can properly read and write Excel files, you can create a simple one and read it back in like this:

//create a sample vector
x = { 9, 1, 4, 7 };

//create a new XLS file and write
//the data from 'x' into it
ret = xlsWrite(x, "test_file.xls", "A1", 1, "");

//read the contents of this new XLS file
//into a new variable
newx = xlsReadM("test_file.xls", "A1", 1, "");

print "x = " x;
print "newx = " newx;

If the above code prints out x and newx both equal, then your Excel reading/writing is working.

Does the Excel file in question exist? If so, can GAUSS read it?
The first step to answer these questions is to change GAUSS's working directory to the directory in which the Excel file should exist. You can do this by either using the working directory toolbar dropdown/button at the top of the GAUSS interface or by using the chdir command, like this:

//Note double back-slashes inside quotes
chdir "C:\\Userelda.c\\Documents\\paper1\\Empirical\\data");

You can confirm that your current working directory is correct with the cdir command like this;

cdir(0);

Now that you have confirmed that the you are in the correct directory, you can check to see if the file is present. Use the filesa command to list all of the files in the current working directory. The star character * is used to represent any number of any characters. So you can list all the files in the current directory like this:

filesa("*");

or if you just want to list files with an .xls extension, you would enter:

filesa("*.xls");

Check the list that this command prints out to see if the file is listed. If not, then GAUSS cannot read it, because it does not exist in this location. If it IS listed, then try to read its contents while it is in GAUSS's current working directory.

test_var = xlsReadSA("es09_1.xls", "A1", 1, "");

aptech

1,773


1



Ok, I am pretty sure that I see the source of the problem now. Your original error regarding the xls file is:

Error in .xlsReadSA: Could not load file C:\Userselda.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

After seeing how you have set up your paths, I can see that the path above is wrong. It should start out: C:\Users\zelda.c, but in the error it is missing the 'z'. It reads C:\Userselda.c. This is most likely stemming from having only a single backslash between 'Users' and 'zelda.c' in the path string.

After confirming that everything else is working, I am quite confident that when you fix this, all will be well. Feel free to post if you need any help with this last part.

aptech

1,773


1



Looking at your error:

G0534 : Cannot create file C:\Users\zelda.fmt ‘C:\Users\zelda.fmt’ [factor_modavg_samplesplit_rolling_1.gss, line 275]

it seems strange that this code would try to create a file in C:\Users and it also seems strange that the file would be part of your user name. This makes me think that there is a problem with the path and file name.

I downloaded and unrar'ed the code. Based upon the information from your error message, it appears that the problem is occurring on these lines:

//The $+ operator combines strings
strname = fmtdir $+ sname $+ "_" $+ ftocv(nph,1,0);
s1 = strname $+ "_rolling";

//Save the contents of the variable 'rslt_save'
//into the filename contained in 's1'
save ^s1=rslt_save;

The first two lines above are creating a string containing a full path and file name. The final line saves the contents of the GAUSS variable rslt_save into that file.

Looking at the second line of code above, we see that the file name should end with _rolling. Since yours does not (based upon the error report), there is probably a single-backslash in the string s1 that is causing the problem.

Take a look at the contents of the string variables strname, fmtdir, sname, strname and s1. This should show the error.

To examine these variables, you can either place a breakpoint on line 275 and run the debugger to that line (the preferred method), or place print statements for each of the variables listed in the paragraph above just before line 275.



0



Thank you for your help - I tried to change the folder permissions to read and write access but no file has been created. However the code runs to completion with no errors.

When I run the factor_modavg_samplesplit_rolling_1.gss file, it says:

Error in .xlsReadSA: Could not load file C:\Userselda.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

However, I have checked the file es09_1.xls is there and has no access issues. Please can you help me understand what I'm doing wrong?

Any help would be greatly appreciated.



0



Hi - thank you for your help. I've tried what you've suggested but I still get the same error message:

Error in .xlsReadSA: Could not load file C:\Userseulah.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

I've double checked that the changes to xls.src have saved and I'm using GAUSS v14. Is there anything else I can try?

Thank you



0



I did the above as instructed as a exceltest.gss file. (For reference I've copied and pasted the commands and output below.) GAUSS seems to read and identify the spreadsheet es09_1.xls fine. But when I run the factor_modavg_samplesplit_rolling_1.gss file it still keeps coming up with the error:

Error in .xlsReadSA: Could not load file C:\Userselda.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

I've also tried creating a new .xls and .xlsx  file, and then copy pasting in the sheets from es09_1.xls to each case, but this yielded the same error message.

I also tried to include the chdir command in the _modavg_samplesplit_rolling_1.gss file to see if that would help, but the "could not load file" error message persists. Is there any way around this?
Many thanks for your help.

 

For reference...

***

exceltest file:

//create a sample vector
x = { 9, 1, 4, 7 };

//create a new XLS file and write
//the data from 'x' into it
ret = xlsWrite(x, "test_file.xls", "A1", 1, "");

//read the contents of this new XLS file
//into a new variable
newx = xlsReadM("test_file.xls", "A1", 1, "");

print "x = " x;
print "newx = " newx;

 

//change and check the working directory
chdir "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data";
cdir(0);
//list all files in directory
filesa("*")
//list files with xls extension
filesa("*.xls")
//check GAUSS can read its contents in the current working directory
xlsReadSA("es09_1.xls", "A1", 1, "");

***

output:

run C:\Users\zelda.c\Documents\paper1\Empirical\data\exceltest
x =
9.0000000
1.0000000
4.0000000
7.0000000
newx =
9.0000000
1.0000000
4.0000000
7.0000000
C:\Users\zelda.c\Documents\paper1\Empirical\data

.
..
es09_1.xls
exceltest
test_file.xls
es09_1.xls
test_file.xls
Name IPS10 IPS11 IPS299 IPS12 IPS13 IPS18 IPS25 IPS32 IPS34 IPS38 IPS43 IPS307 IPS306 PMP UTL11 CES275 CES277 (there is more that I've chosen not to copy and paste)

 

 



0



Just tried that out and it works! Thanks very much.  However now I'm getting an error message similar to the one I faced at the start:

G0534 : Cannot create file C:\Users\zelda.fmt 'C:\Users\zelda.fmt' [factor_modavg_samplesplit_rolling_1.gss, line 275]

I have tried checking the properties to ensure the folder has read and write access, my account is also the sole user on my laptop so I'm the admin user too. Is there a way of checking why the file cannot be created? I've only just started using GAUSS so I don't know if this is an issue to do with all files GAUSS creates, or just the rolling_1.gss file I'm trying to run.

I've also tried creating the file in c:\\fmt and in the working directory C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data\\ - both give the same error message above exactly.

Many thanks for your help.

***

For ref: the code I am running is available from http://www.ssc.wisc.edu/~bhansen/progs/factor.html. I'm looking specifically at factor_modavg__samplesplit_rolling_1.gss. My file differs from the original only in lines 21 - 25 and  49-52 which are file paths. Up to line 52 mine reads:

new;
cls;
outwidth 256;
library pgraph;
graphset;
chdir "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data";
xlsname="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data\\es09_1.xls"; @ DATA Set (Excel File) @
outdir="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\out\\";
fmtdir="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\fmt\\";
figdir="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\fig\\";

 

/* Section 1. Construct Data and Rolling Forecast with AR(4), OLS, and DFM5
This part is taken from Mark Watson's progam*/

ifest=3; @ First Observation to Use for estimation -- eliminate 2 obs for second differences @
nfirst = 1960.0;
nlast = 2008.99;

@ -- Parameters for Outlier Adjustment -- @
ioutlier=1; @ = 1 for correcting outliers in X @
thr=6; @ Threshold multiple for IQR @
@ -- Parameters for Forecast ---- @
nphvec = 1|2|4|8|12;
nar = 4; @ Zero for No AR terms @

nfac = 50; @ Number of factors @
troll = 100; @ Number of Obs in rolling Sample @
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\calendar.gss";
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\readxls.prc";
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\fcst.prc";
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\datain.gss";

Your Answer

9 Answers

1

That error means that the user account that is running GAUSS does not have write permissions in that directory. You will need to have the file created in another folder on your computer.

If you have any questions about how to do that, please ask!

1

This error is probably happening because you do not have Excel installed on your computer. The standard method that GAUSS for Windows uses to read and write Excel files requires Excel to be installed on your computer.

If you have GAUSS 13 or later, there is also another method available that does NOT require Excel to be installed. On Linux and Mac, this is the default. To turn this on for Windows, you will need to edit your xls.src file. You can open this file by entering:

edit xls.src

from the GAUSS command line. Around lines 38-40, you should see this code:

#ifOS2WIN
   #define USECOMEXCEL 1
#endif

You need to comment all out all three of these lines. When you have done this, they should look like this:

//#ifOS2WIN
//   #define USECOMEXCEL 1
//#endif

Now that this is done, you should run the xls.src file so that GAUSS has the updated definitions. You can do this by entering:

run xls.src

from the GAUSS command line.

1

It is possible that the file is in a very old Excel file format. The GAUSS library that does not call Excel, but reads and writes the files directly cannot read files in formats older than the Excel 97-2003 format. That is a possibility, but would be a little surprising. If this is the case, you can open the file with Excel and then save it as a newer format Excel file. This should solve your problem. However, it is worth trying one more thing to make sure that you are not making another mistake.

Verify that reading/writing of Excel files is working
To find out if your GAUSS set up can properly read and write Excel files, you can create a simple one and read it back in like this:

//create a sample vector
x = { 9, 1, 4, 7 };

//create a new XLS file and write
//the data from 'x' into it
ret = xlsWrite(x, "test_file.xls", "A1", 1, "");

//read the contents of this new XLS file
//into a new variable
newx = xlsReadM("test_file.xls", "A1", 1, "");

print "x = " x;
print "newx = " newx;

If the above code prints out x and newx both equal, then your Excel reading/writing is working.

Does the Excel file in question exist? If so, can GAUSS read it?
The first step to answer these questions is to change GAUSS's working directory to the directory in which the Excel file should exist. You can do this by either using the working directory toolbar dropdown/button at the top of the GAUSS interface or by using the chdir command, like this:

//Note double back-slashes inside quotes
chdir "C:\\Userelda.c\\Documents\\paper1\\Empirical\\data");

You can confirm that your current working directory is correct with the cdir command like this;

cdir(0);

Now that you have confirmed that the you are in the correct directory, you can check to see if the file is present. Use the filesa command to list all of the files in the current working directory. The star character * is used to represent any number of any characters. So you can list all the files in the current directory like this:

filesa("*");

or if you just want to list files with an .xls extension, you would enter:

filesa("*.xls");

Check the list that this command prints out to see if the file is listed. If not, then GAUSS cannot read it, because it does not exist in this location. If it IS listed, then try to read its contents while it is in GAUSS's current working directory.

test_var = xlsReadSA("es09_1.xls", "A1", 1, "");
1

Ok, I am pretty sure that I see the source of the problem now. Your original error regarding the xls file is:

Error in .xlsReadSA: Could not load file C:\Userselda.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

After seeing how you have set up your paths, I can see that the path above is wrong. It should start out: C:\Users\zelda.c, but in the error it is missing the 'z'. It reads C:\Userselda.c. This is most likely stemming from having only a single backslash between 'Users' and 'zelda.c' in the path string.

After confirming that everything else is working, I am quite confident that when you fix this, all will be well. Feel free to post if you need any help with this last part.

1

Looking at your error:

G0534 : Cannot create file C:\Users\zelda.fmt ‘C:\Users\zelda.fmt’ [factor_modavg_samplesplit_rolling_1.gss, line 275]

it seems strange that this code would try to create a file in C:\Users and it also seems strange that the file would be part of your user name. This makes me think that there is a problem with the path and file name.

I downloaded and unrar'ed the code. Based upon the information from your error message, it appears that the problem is occurring on these lines:

//The $+ operator combines strings
strname = fmtdir $+ sname $+ "_" $+ ftocv(nph,1,0);
s1 = strname $+ "_rolling";

//Save the contents of the variable 'rslt_save'
//into the filename contained in 's1'
save ^s1=rslt_save;

The first two lines above are creating a string containing a full path and file name. The final line saves the contents of the GAUSS variable rslt_save into that file.

Looking at the second line of code above, we see that the file name should end with _rolling. Since yours does not (based upon the error report), there is probably a single-backslash in the string s1 that is causing the problem.

Take a look at the contents of the string variables strname, fmtdir, sname, strname and s1. This should show the error.

To examine these variables, you can either place a breakpoint on line 275 and run the debugger to that line (the preferred method), or place print statements for each of the variables listed in the paragraph above just before line 275.

0

Thank you for your help - I tried to change the folder permissions to read and write access but no file has been created. However the code runs to completion with no errors.

When I run the factor_modavg_samplesplit_rolling_1.gss file, it says:

Error in .xlsReadSA: Could not load file C:\Userselda.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

However, I have checked the file es09_1.xls is there and has no access issues. Please can you help me understand what I'm doing wrong?

Any help would be greatly appreciated.

0

Hi - thank you for your help. I've tried what you've suggested but I still get the same error message:

Error in .xlsReadSA: Could not load file C:\Userseulah.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

I've double checked that the changes to xls.src have saved and I'm using GAUSS v14. Is there anything else I can try?

Thank you

0

I did the above as instructed as a exceltest.gss file. (For reference I've copied and pasted the commands and output below.) GAUSS seems to read and identify the spreadsheet es09_1.xls fine. But when I run the factor_modavg_samplesplit_rolling_1.gss file it still keeps coming up with the error:

Error in .xlsReadSA: Could not load file C:\Userselda.c\Documents\paper1\Empirical\data\es09_1.xls [xls.src, line 226]

I've also tried creating a new .xls and .xlsx  file, and then copy pasting in the sheets from es09_1.xls to each case, but this yielded the same error message.

I also tried to include the chdir command in the _modavg_samplesplit_rolling_1.gss file to see if that would help, but the "could not load file" error message persists. Is there any way around this?
Many thanks for your help.

 

For reference...

***

exceltest file:

//create a sample vector
x = { 9, 1, 4, 7 };

//create a new XLS file and write
//the data from 'x' into it
ret = xlsWrite(x, "test_file.xls", "A1", 1, "");

//read the contents of this new XLS file
//into a new variable
newx = xlsReadM("test_file.xls", "A1", 1, "");

print "x = " x;
print "newx = " newx;

 

//change and check the working directory
chdir "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data";
cdir(0);
//list all files in directory
filesa("*")
//list files with xls extension
filesa("*.xls")
//check GAUSS can read its contents in the current working directory
xlsReadSA("es09_1.xls", "A1", 1, "");

***

output:

run C:\Users\zelda.c\Documents\paper1\Empirical\data\exceltest
x =
9.0000000
1.0000000
4.0000000
7.0000000
newx =
9.0000000
1.0000000
4.0000000
7.0000000
C:\Users\zelda.c\Documents\paper1\Empirical\data

.
..
es09_1.xls
exceltest
test_file.xls
es09_1.xls
test_file.xls
Name IPS10 IPS11 IPS299 IPS12 IPS13 IPS18 IPS25 IPS32 IPS34 IPS38 IPS43 IPS307 IPS306 PMP UTL11 CES275 CES277 (there is more that I've chosen not to copy and paste)

 

 

0

Just tried that out and it works! Thanks very much.  However now I'm getting an error message similar to the one I faced at the start:

G0534 : Cannot create file C:\Users\zelda.fmt 'C:\Users\zelda.fmt' [factor_modavg_samplesplit_rolling_1.gss, line 275]

I have tried checking the properties to ensure the folder has read and write access, my account is also the sole user on my laptop so I'm the admin user too. Is there a way of checking why the file cannot be created? I've only just started using GAUSS so I don't know if this is an issue to do with all files GAUSS creates, or just the rolling_1.gss file I'm trying to run.

I've also tried creating the file in c:\\fmt and in the working directory C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data\\ - both give the same error message above exactly.

Many thanks for your help.

***

For ref: the code I am running is available from http://www.ssc.wisc.edu/~bhansen/progs/factor.html. I'm looking specifically at factor_modavg__samplesplit_rolling_1.gss. My file differs from the original only in lines 21 - 25 and  49-52 which are file paths. Up to line 52 mine reads:

new;
cls;
outwidth 256;
library pgraph;
graphset;
chdir "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data";
xlsname="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\data\\es09_1.xls"; @ DATA Set (Excel File) @
outdir="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\out\\";
fmtdir="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\fmt\\";
figdir="C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\fig\\";

 

/* Section 1. Construct Data and Rolling Forecast with AR(4), OLS, and DFM5
This part is taken from Mark Watson's progam*/

ifest=3; @ First Observation to Use for estimation -- eliminate 2 obs for second differences @
nfirst = 1960.0;
nlast = 2008.99;

@ -- Parameters for Outlier Adjustment -- @
ioutlier=1; @ = 1 for correcting outliers in X @
thr=6; @ Threshold multiple for IQR @
@ -- Parameters for Forecast ---- @
nphvec = 1|2|4|8|12;
nar = 4; @ Zero for No AR terms @

nfac = 50; @ Number of factors @
troll = 100; @ Number of Obs in rolling Sample @
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\calendar.gss";
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\readxls.prc";
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\fcst.prc";
#include "C:\\Users\\zelda.c\\Documents\\paper1\\Empirical\\datain.gss";


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy