dear listers,
(i use intercooled version 8.2 under win2000)
i just found this odd thing when trying to transfer a couple of *.dbf files
to *.txt and using a stata do file to automate the process. consider this
simple cycle (stata is now in parent dir of dir1 and dir2):
foreach subdir in dir1 dir2 {
cd `subdir'
* winexec "C:\Program Files\StatTransfer6\st" *.dbf *.txt
* !"C:\Program Files\StatTransfer6\st.exe" *.dbf *.txt
cd ..
}
...and think about two different scenarios, each with one of the now
commented-out lines activated.
the one beginning with -!- (or -shell-) will work fine, but the -winexec-
one will not. in fact, the txt files will be corrupted, with several records
(looks like every 16th starting from the 7th) gone missing during the
transfer, though the variable structure will be ok.
however, if my code is based on repetition rather than a cycle:
cd dir1
winexec ...
cd ../dir2
winexec ...
cd ..
...everything is fine. you might think it has something to do with stata not
waiting for stattransfer to complete in case of -winexec-. right, but if the
subdirectory is built into the file path rather than changed:
foreach subdir in dir1 dir2 {
winexec "C:\Program Files\StatTransfer6\st.exe" `subdir'\*.dbf
`subdir'\*.txt
}
everything will be fine, too, so winexec can be worked from within the
cycle, just do not change directories. then again, if the slash is
incorporated into the foreach items in this latest code:
foreach subdir in "dir1/" "dir2/" {
or
foreach subdir in "dir1\" "dir2\" {
then
... `subdir'*.dbf `subdir'*.txt
...the transfer will be completed, but will be ok with -shell-/-!- only and
corrupted with -winexec-.
i don't know if this is specific to stattransfer or not, but i do not think
that is the point. something tells me that if a command works fine (i.e. as
you would expect as a user, based on the manual) outside a -foreach- cycle,
and its near synonymous commands work both in- and outside such a cycle,
then that command itself should work fine inside -foreach-, even if you go
as far as change directories in preceding and subsequent commands. or if
not, it should not work at all.
has anyone seen this before? is this something like having to use
==float(1.23) instead of ==1.23, a perfectly logical thing you just need to
be told about once and you will agree that it should be so? no hints in faq
or anywhere after a decent (though not the most rigorous) search.
thanks in advance
laszlo
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/