Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: read files under certain directory automatically


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: read files under certain directory automatically
Date   Mon, 18 Jul 2005 19:02:56 +0100

It is easy to put a set of file names in a macro
using a macro extended function: 

{local | global} macname :  dir ["]dirname["] {files|dirs|other}
                                    ["]pattern["] [, nofail ]

-fs- is a convenience command canning this on SSC. 

Having done that, the most obvious way to do what you 
outline would seem to be a loop over the files using -foreach-. 
Note that with -describe using-, you do not need to 
read in any file to get at the number of observations. 

So, for example,  

fs *.dta 
foreach f in `r(files)' { 
	qui d using `"`f'"' 
	di `"`f'"' "   " `r(N)' 
} 

displays information for all .dta files in the current directory. 

Adding files is not discussed here. 

Nick 
[email protected] 

Luhang Wang
 
> Can stata put all the file names of data sets under certain directory
> into a macro? Or is there some other way to read the data sets under
> certain directory antomaticcally?
> 
> To be more specific, what I'm trying to do is to open the data sets
> under some directory and count the observations, and I may add files
> to that directory. Many thanks!

*
*   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/



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