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.
Best,
Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
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
dr(608)
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
Roy
_________________________________________________________________
Hotmail® has a new way to see what's up with your friends.
http://windowslive.com/Tutorial/Hotmail/WhatsNew?ocid=TXT_TAGLM_WL_HM_Tutorial_WhatsNew1_052009
*
* 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/