Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: importing multiple text files


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: importing multiple text files
Date   Fri, 4 Feb 2011 18:27:27 +0000

>
There's also a simpler version of this macro extended functions approach in section  //2.//  of this message:  http://www.stata.com/statalist/archive/2010-08/msg00751.html
Though I think you want to use -append- to combine all your files, not -merge- (sim. to the thread mentioned in my previous post), but it might be easier to follow the loop in this message.

- Eric
________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Eric Booth [ebooth@ppri.tamu.edu]
Sent: Friday, February 04, 2011 12:18 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: importing multiple text files

>
Yes, it's possible.  Take a look at the macro extended functions (help extended_fcn) for selecting all files in directories--you can work with these in a loop to select each file in a folder(s) and append/merge them all together.
Here are two threads that do something similar to what you describe (including creating a variable (called 'filename') that identifies the file each record came from).

http://www.stata.com/statalist/archive/2010-11/msg00113.html

http://www.stata.com/statalist/archive/2010-01/msg00238.html

- Eric
________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Harry Comber [h.comber@ncri.ie]
Sent: Friday, February 04, 2011 12:01 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: importing multiple text files

I have 304 text files (Windows, comma-separated) with identical
structures (5 numeric variables) from 304 different cancer registries,
which I would like to import into Stata 10 and combine into a single
file. Each file has about 10,000 observations.  The files are named
using a unique numeric identifier for the registry from which it comes
(e.g. 38408099.csv) and I would like to also import this number as a
variable into the file in order to identify the data from that registry.
This is beyond my programming skills and I am not even sure it is
possible. I would appreciate some advice.

Harry Comber

------------------------------------------------------------------------
--
Dr. Harry Comber, Director
National Cancer Registry (www.ncri.ie)
Building 6800
Cork Airport Business Park
Kinsale Road
Cork.
Tel  +353 21 4318014
Fax +353 21 4318016
Email: h.comber@ncri.ie
------------------------------------------------------------------------
-------
The contents of this email are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorised designee, you may not copy or use it, or
disclose it to anyone else. If you have received it in error please
notify us immediately and then destroy it. The NCRI does not guarantee
the security of any information electronically transmitted and is not
liable if the information contained in this communication is not a
proper and complete record of the message as transmitted by the sender
or for any delay in its receipt.

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

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index