Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Stata thinks files are read-only when they shouldn't be!


From   "Eric A. Booth" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Stata thinks files are read-only when they shouldn't be!
Date   Sun, 10 May 2009 13:37:54 -0500

Two things come to mind, either (1) your computer/OS is capriciously setting your file with a read-only attribute (as Nick points out, this can happen with Windows XP) or (2) when Stata tells the OS to write the file to myfile_happ.txt, the OS is moving too slowly, Stata moves on to the next loop and tries to write again, but the file is read- only because it is still being written to by the OS (or BOTH (1) and (2) are happening).

The solution to (1) is to "force" xp to apply a read-write, rather than a read-only, attribute to your file using the -winexec attrib- command and the solution to (2) is to tell Stata to slow down in your loop so that it isn't outpacing your OS by using the -sleep- command.

So your new loop might look like:


foreach y of varlist happ job  {
	regress `y' lrwage lrwager firm_l if female==1, cluster(unm)
estimates store Self0
	regress `y' lrwage lrwager firm_l firm_iqr if female==1,
cluster(unm)	estimates store Self1
       ...
       outreg2 lrwage lrwager firm_l firm_iqr [Self0 Self1 ...]  ///
	using myfile_`y', replace bdec(2) label nocons excel
	sleep 8000
	winexec attrib -R "c:\yourpath\yourfolder\myfile_`y'.txt"    /S     /D
}


Depending on your version and SP of Windows XP you may need to modify the -winexec attrib- command above. Generally, the DOS command follows the format:

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [[drive:] [path] filename] [/S [/D]]

but you should open DOS and try "attrib /?" or "help attrib" (? I can't remember what the help command in Windows XP DOS, it's been a while) to see what format it asks for. The "-R" part is telling the computer to remove any read-only attribute of the file.

The combination of the sleep command to ask Stata to wait up a bit and the attrib command to force the OS to make sure the file is read-only before it loops again should do the trick.

Good luck.

Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249



On May 10, 2009, at 9:44 AM, Nick Cox wrote:

-outreg2- is a user-written program (Roy Wada, SSC).

Broadly speaking, my guess is that the explanation is nothing to do with
either the official Stata commands you use or -outreg2-. It will be a
matter of how that directory is set up within Windows. I know this
contradicts what you say, but it's still my guess, because I can't think
of a better one.

So I'd seek an explanation the operating system end.

I've known Windows decide -- utterly capriciously, from my point  of
view, although presumably it was a consequence of something I did --
that a particular directory was read-only.

The fact that you report that this "sometimes" happens seems consistent
with that guess.

Conversely, if this were a bug in the commands mentioned, all heavily
used, it would have been reported long since.

Nick
[email protected]

kokootchke

Sometimes when I run do files in which I try to save, replace or modify
a file in some way, Stata thinks that this file is read-only when it
shouldn't be.
The problem I'm having right now is the following:
I am running a do file that contains a bunch of lines like:


foreach y of varlist happ job{
	regress `y' lrwage lrwager firm_l if female==1, cluster(unm)
estimates store Self0
	regress `y' lrwage lrwager firm_l firm_iqr if female==1,
cluster(unm)	estimates store Self1
       ...
       outreg2 lrwage lrwager firm_l firm_iqr [Self0 Self1 ...] using
myfile_`y', replace bdec(2) label nocons excel}


When I do the file, I notice that Stata shows in the display window the results for all the regressions but when it reaches the outreg2 command,
it gives the following error:

file myfile_happ.txt is read-only; cannot be modified or erasedr(608);

And I get this error whether myfile_happ.txt exists in the directory or
not. Also, sometimes I only get this error for the SECOND time Stata
goes through the loop; that is, the first time it goes through and it
does save the file myfile_happ.txt but the second time it stops and it
fails to save the file myfile_job.txt!!! What do you think is going on??

Another thing that happens often -- but I'm not having this problem
right now -- is that I run a do file that contains a line such as:
save, replace
and it fails to save the file because it is apparently read-only. What
is even stranger is that some other times, it does go through and saves
the file normally.
I have already verified that my folder where my files are in Windows is
not read-only, but that doesn't help.
I am running Stata 9 SE on Windows XP Pro... but I think I have also
seen this error when I've run my code on a different computer with Stata
10 SE.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index