Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Problems with insheet within a foreach loop


From   "Eva Poen" <[email protected]>
To   [email protected]
Subject   Re: st: Problems with insheet within a foreach loop
Date   Wed, 23 Jul 2008 14:07:50 +0100

Paul,

in Stata 9 and 10, I can use -insheet- and -outsheet- inside a loop
without any problems.

Have you actually changed directory before the insheet commands? The
-local mort : - statement only stores the file names and not the
directory name. If -pwd- does not show "P:/Public Health/...(very long
directory path here)", it might be that there is a file named
p5a8ap07.txt in your current working directory, but not a file called
p5a8au07.txt. You'd have to either -cd- to your directory, or include
the path into the insheet statement to achieve what you want.

Hope this helps,
Eva

2008/7/23 Paul McCabe <[email protected]>:
> Dear Statlisters
>
> I am trying to read file names from a folder prior to processing and appending.
>
> My local appears to be picking up the names - see log part A below.
> The foreach loop appears to be having problems with insheet-ing -
> specifically an r(601) error message that a file is not found - see
> log part B below.
> The source file is where it should be and I'm blank.
>
> Any ideas what may be causing this?
>
> Many thanks
> Paul
>
>
> log A
>
> . local mort: dir "P:/Public Health/Vital Statistics_R/ONS Monthly PH
> Files/ONS Monthly PH Mortality Files/2007-08/Raw Data/texts/" files
> "*.txt"
>
> . foreach file of local mort {
>  2.         di "`file'"
>  3.
>      }
> p5a8ap07.txt
> p5a8au07.txt
> p5a8de07.txt
> p5a8fe08.txt
> p5a8ja08.txt
> p5a8jl07.txt
> p5a8jn07.txt
> p5a8mr08.txt
> p5a8my07.txt
> p5a8no07.txt
> p5a8oc07.txt
> p5a8se07.txt
>
> .
> end of do-file
>
> log B
> . local mort: dir "P:/Public Health/Vital Statistics_R/ONS Monthly PH
> Files/ONS Monthly PH Mortality Files/2007-08/Raw Data/texts/" files
> "*.txt"
>
> . foreach file of local mort {
>  2.         di "`file'"
>  3.         insheet using `file'
>  4.         clear
>  5.         di "`file'"
>  6.         }
> p5a8ap07.txt
> (87 vars, 171 obs)               **This insheet appears to work
> p5a8ap07.txt
> p5a8au07.txt
> file p5a8au07.txt not found   **This one doesn't
> r(601);
>
> end of do-file
> r(601);
> *
> *   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