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: read in file with varying # of observations


From   Caleb Southworth <[email protected]>
To   [email protected]
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

File1
* 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
7
3
2

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
times.

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.

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