Bookmark and Share

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

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

st: Re: Controlling record length in ASCII file imports

From   "Joseph Coveney" <>
To   <>
Subject   st: Re: Controlling record length in ASCII file imports
Date   Tue, 10 Aug 2010 23:46:56 +0900

Nathan Hutto wrote:

I am trying to import raw data from an ASCII file into Stata and am
failing. There should be about 800 observations, but I am importing
only 200 or so. I tried this using infix and writing a dictionary
file. I realized afterwards that the ASCII file is formatted poorly:
the data are not in nice, neat columns and each observation does not
start on a new line (i.e., observation 1 is on line one and
observation 2 begins at the end of observation 1 and perhaps wraps
around to line 2). I'm not quite sure of the most efficient way to
approach this, especially given that I have about 10 of these files
with about 800 observations each. It seems like I could manually put
each observation on a new line, but that would take a while. Is there
a way to specifiy record length? Or another option?


There is a way to specify record length in a dictionary.  The option is 
_lrecl(#).  Type

help infile2

at the command line to see more information.  The help file says that it's 
intended for files that have no end-of-line delimiters.  From your description, 
your file does have them, so your best bet in its use is to first get rid of 
all carriage return-line feed (or whatever) ASCII character pairs in your 
dataset  before using this approach.  Stata's -filefilter- command handles this
well.  Type 

help filefilter

at the command line in order to see more.

There are probably other approaches, too, perhaps easier than this one, but it
would be better to show the list more about what exactly it is that you're 
facing to get anything more specific.

Joseph Coveney

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index