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

st: re: renaming files


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: renaming files
Date   Wed, 29 Dec 2004 22:41:57 -0500

Rafal said

Let's say I have data on imports to the U.S., commodity by country, on a yearly
basis (such as Feenstra's TSUSA Imports). The original data are in txt format
and there are three txt files per year. Assume file names are completely
random but all the files have identical layout (var names, type, etc.).

Now I want to infile the txt files into Stata, save them in dta format as
import1, import2, ... , import51...

forvalues i = 1(1)51 {
infile using C:\Imports\import`i'.txt
save import`i'
clear
}

... and then I want to create one huge dataset:

use import1
forvalues i = 2(1)51 {
append using import`i'
}
save import-big


Since all you're going to do is append all these files together, do that at the operating system level, and read just one file into Stata:

!cat *.txt > allfiles.raw
infile using allfiles.raw

or whatever is the equivalent construction in your OS.

Alternatively, use fs:

fs *dta
foreach f in `r(files)' {
use `f',clear
desc
}


Kit Baum, Boston College Economics [email protected]
http://ideas.repec.org/e/pba1.html

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