Statalist


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

st: Importing text file into Stata


From   Eve Corda <eve.corda@inserm.fr>
To   statalist@hsphsun2.harvard.edu
Subject   st: Importing text file into Stata
Date   Thu, 29 Oct 2009 10:05:49 +0100

Dear all,

I have problems importing some kind of text files into Stata. The files I want to import are separated by several spaces and have a header line. If I remove the header line I can use the -infile- command (free format) while specifying variable names and string variables, which might look like:

infile variable_list using myfile.txt

The problem is I have dozens of such files to import and I don't want to duplicate them, having one copy with headers and another copy without headers. The -infile- command allows to import only a subset of observations by specifying -in range- but then I need to know the row number of each file.

Do you know how I can retreive the row number of an external text file, and then use it in a do file as a macro variable `row_no', in a command such as:
infile variable_list in 2/`row_no' using myfile.txt

Or maybe you have another way to solve my problem?

The -infix- command is not a good solution as the variables are not always located within the same columns in text file.

Thanks a lot in advance for your help.

Best wishes,

Eve


--
Eve CORDA
Statistician

Fondation Jean DAUSSET / CEPH
Unité INSERM U946 (ex U794) - 4ème étage
27 Rue Juliette Dodu
75010 PARIS FRANCE
Tel: +33 (0)1 53 72 50 22
Fax: +33 (0)1 53 72 50 49
e-mail: eve.corda@inserm.fr


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index