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

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

From   "Eric A. Booth" <>
Subject   Re: st: Stata thinks files are read-only when they shouldn't be!
Date   Sun, 10 May 2009 22:59:29 -0500

Roy is right that the problem might be that Adrian is opening his text file before Stata has finished. Additionally, it might be that Adrian has opened the text file, left it open, and tried to run the do-file again. If so, this may produce the same error.

So, to add to my previous suggestions about telling DOS to give read- write attributes to the text file and telling Stata to sleep for a bit, maybe Adrian needs to add a command to tell Windows to close his text program before running each iteration of the loop, just in case he left it open or he tries to peek at it too early.

So you might add the line:

	winexec taskkill /F /IM Notepad.exe /T

if you were using Windows XP and you were opening your "myfile_happ.txt" file in notepad. You'll need to adjust this according to the program you are using to look at the .txt file.

Additionally, if you are using Mac or linux, you can use the command:

	!osascript -e 'tell application "TextEdit" to quit'

to close the text editor (if you were using TextEdit in MacOSX to look at your .txt file).

You can put this line at the beginning of your loop and the OS will ignore it if you've already closed the text editor.



Eric A. Booth
Public Policy Research Institute
Texas A&M University
Office: +979.845.6754

On May 10, 2009, at 8:03 PM, Roy Wada wrote:

outreg2 lrwage lrwager firm_l firm_iqr [Self0 Self1 ...]
using myfile_`y', replace bdec(2) label nocons excel}

file myfile_happ.txt is read-only; cannot be modified or erased

And I get this error whether myfile_happ.txt exists in the directory
or not.

You usually get this error when the file is being used by another software,
usually Excel or Word. This happens when you peek at the output while
-outreg2- is still running. This makes the file "read-only" to Stata.

The solution is to close the file and don't open it until Stata has
finished running. Because Adrian's problem is intermittent, this might
be the case.

If you want to look at an -outreg2- file while it is still running, then you should copy-and-paste the file (control-c, control-v), and then look
at the duplicated file.

I think this is mentioned somewhere in the help file (not leave the file open), but a smart thing is for -outreg2- to send its own error message
telling you to close the file.

If this cannot be done, then it needs to be put in the help file


Hotmail® has a new way to see what's up with your friends.
*   For searches and help try:

*   For searches and help try:

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