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: complete data import
From
Douglas Levy <[email protected]>
To
[email protected]
Subject
st: complete data import
Date
Mon, 7 Apr 2014 15:45:48 -0400
Hi All,
I have a complicated .csv file that I'm trying to import and I'm
hoping you can provide some guidance on the best strategy. See the
example below. Each record in the file consists of up to 3 line types
labeled "MEM", "ITM", and "TND". Each line type has a particular
format. For example, "MEM" line types have var1, var2, and var3. "ITM"
has var4, var5, and var6. Etc. Each record may or may not have a "MEM"
line, has 1 or more "ITM" lines, and has 1 "TND" line that ends the
record. A record is defined as ending with the "TND" line. The "MEM"
line may come at any point in the record, but is often first.
Example data
ITM,S,0,1,1.35,5100001261,soup,
TND,N,0,0,0,1.35,0,0
ITM,S,0,1,1.35,5100001261,soup,
TND,N,0,0,0,1.35,0,0
MEM,N,280211400001,,,,,
ITM,S,0,1,1.35,5100001261,soup,
TND,N,0,0,0,0,11.28,0
ITM,S,0,1,1.29,5000001011,milk,
TND,N,0,0,0,1.29,0,0
MEM,N,280211400159,,,,,
ITM,S,0,1,1.29,5000001011,milk,
ITM,S,0,1,1.29,5000001011,milk,
ITM,S,0,1,1.29,5000001011,milk,
TND,N,4,0,0,0,0,0
I'd like to attach a unique record identifier the "TND" line and I'd
like to attach the "TND" and "MEM" info for a given record to each
"ITM" line in the record. Ultimately, I'd like the Stata file for the
above data to look like this, where the number after "soup" or "milk"
is the record identifier (placement of that variable is not
important):
ITM,S,0,1,1.35,5100001261,soup, 1, TND,N,0,0,0,1.35,0,0
ITM,S,0,1,1.35,5100001261,soup, 2, TND,N,0,0,0,1.35,0,0
ITM,S,0,1,1.35,5100001261,soup, 3, TND,N,0,0,0,0,11.28,0,
MEM,N,280211400001,,,,,
ITM,S,0,1,1.29,5000001011,milk, 4, TND,N,0,0,0,1.29,0,0
ITM,S,0,1,1.29,5000001011,milk, 5, TND,N,4,0,0,0,0,0, MEM,N,280211400159,,,,,
ITM,S,0,1,1.29,5000001011,milk, 5, TND,N,4,0,0,0,0,0, MEM,N,280211400159,,,,,
ITM,S,0,1,1.29,5000001011,milk, 5, TND,N,4,0,0,0,0,0, MEM,N,280211400159,,,,,
Any advice would be most welcome!
Best,
Doug
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/