Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: How to read in an irregular ASCII-file?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: How to read in an irregular ASCII-file?
Date   Wed, 12 Jan 2005 21:21:05 -0000

-strparse- was the precursor of official Stata's 
-split-. From what I can remember the syntax 
would be identical here. 

Nick 
[email protected] 

[email protected] replied to Barbara Hofmann <[email protected]>

> > i want to read in a ascii-dataset of a structure like this:
> > 
> > 104525300010   9064496 022    999929912
> > 204525300010   9064496 1:19 59 22  2:4 0 96   3:8 0 92  4:0 33 67
> > 204525300010   9064496            6:30 50 20  7:78 5 17
> > 104525300010   9081400 023    23131122
> > 104525300020             7    332321332 06 00 05 2264
> > 104525300020             8    221211121 06 00 09 1889
> > 104525300020             8    222222222 06 00 08 4705
> > 104525300020             8    231211222 06 00 06 4585
> > 
> > 
> > "2" in the first column means that this line belongs to the line 
> > before. column 31-39 include replies to 9 different questions. if 
> > it is a "9" this means, that in the following line there is a more 
> > specific answer to this question which is stored like this:
> > 7:78 5 17 means "78% replied to question 7 with a "1", 5% replied 
> > to question 7 with a "2" and 17% replied to question 7 with a "3""
> > 
> > Then ":" signalizes that the answers to the question of the number 
> > before ":" will follow. How can i tell Stata this meaning of ":"? 
> > Maybe also a problem could be that the answers can be like "10 90 
> > 0" as well as like "15 15 70" or "5 5 90"?
> > 

 
> As a start, the commands below, I believe, pull out the 
> relevant information. 
> It uses Michael Blasnik and Nick Cox’s –strparse- command.
> 
> insheet using "C:\Documents and 
> Settings\scott.merryman\Desktop\foo.txt", clear
> gen id = substr(v1, 1,1)
> 
> forv i = 31/39 {
> 	gen question`i' = substr(v1, `i', 1) if id == "1"
> }
> 
> gen answer = substr(v1, 23,.) if id == "2"
> 
> strparse answer, g(b)
> 
> forv i = 1/12 {
> 	strparse b`i' , gen(detail`i') parse(:)
> }
> 
> drop b*
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index