Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: read in file with varying # of observations

From   Caleb Southworth <>
Subject   st: read in file with varying # of observations
Date   Fri, 24 Feb 2012 14:52:59 -0800

Dear All,

I would like to read in a textfile that has a mixture of id and
variable and repeated ids and variables. The file is stacked (sets of
observations separated by *). For example

* rem 1
* rem 2: var are id value N=100
1 90
2 32
3 34
* rem 3: var are id tie value N=225
1 2 20
1 3 15
2 3 10
3 1 15
3 2 10
3 4 10
* rem 4: one measure in id order N=100

The goal is to end up with one relational file and one dataset with
100 observations.

My start was to read the first part of the file:
infile id val using text.txt if _n<101, clear
save tmp1, replace
infile id tie cat using text.txt if _n>100, clear
save tmp2, replace

My difficulty with this strategy is that I don't know what N will be
for many different files. I need to repeat the process a few hundred

Two questions here: (1) is there a way to get infile to stop when it
encounters an asterisk? (2) perhaps there is some way to have stata
read data between one remark and another? Or some other method of
identifying the sections in a multi-part text file?

Thanks so much for your insights.

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index