It is not clear to me what the final data set should look like, but
perhaps this can help:
clear
input str68 v1
"ANY 1206 Bunk1 Corn Silage $0.00 97 FarmGrown Forag lb"
" 1234 Shed1 Grass Hay $0.00 146 Purchased Forag lb"
" 1582 Purch1 Straw $0.00 164 Purchased Forag lb"
" 1237 Shor1 Haylage 1st cut $0.00 149 FarmGrown Forag lb"
" 1238 Bunk4 Haylage 2nd cut $0.00 150 FarmGrown Forag lb"
" 1070 CornGrainGrndFine $135.00 205 Purchased Energ lb"
" 039 BakeryByProdBread $130.00 308 Purchased Energ lb"
" 1052 BeetPulpPlCp $140.00 313 Purchased Energ lb"
" 1022 EnergyBooster $1,200. 521 Purchased Energ lb"
" 00"
end
qui {
gen var1 = substr(v1,1,3)
replace v1 = substr(v1,4,.)
split v1, limit(1) gen(foo)
gen v2 = reverse(v1)
split v2, gen(R)
foreach var of varlist R* {
replace `var' = reverse(`var')
}
drop v2 R6-R10
rename foo R6
forv j = 1/6 {
forv i = 1/10 {
local a = v1[`i']
local r`j' = R`j'[`i']
local b : list a - r`j'
replace v1 = "`b'" in `i'
}
}
replace R5 = subinstr(R5,"$","",.)
replace R5 = subinstr(R5,",","",.)
gen price = real(R5)
format price %8.2f
drop R5
compress
order var1 R6 v1 price R4 R3 R2 R1
}
l, clean noobs
Which produces:
var1 R6 v1 price R4 R3
R2 R1
ANY 1206 Bunk1 Corn Silage 0.00 97 FarmGrown
Forag lb
1234 Shed1 Grass Hay 0.00 146 Purchased
Forag lb
1582 Purch1 Straw 0.00 164 Purchased
Forag lb
1237 Shor1 Haylage 1st cut 0.00 149 FarmGrown
Forag lb
1238 Bunk4 Haylage 2nd cut 0.00 150 FarmGrown
Forag lb
1070 CornGrainGrndFine 135.00 205 Purchased
Energ lb
039 BakeryByProdBread 130.00 308 Purchased
Energ lb
1052 BeetPulpPlCp 140.00 313 Purchased
Energ lb
1022 EnergyBooster 1200.00 521 Purchased
Energ lb
00 . 00
Scott
----- Original Message -----
From: "Dr. Buzz Burhans" <[email protected]>
Date: Wednesday, January 24, 2007 6:08 am
Subject: RE: st: importing "irregular" columns with embedded blanks
To: [email protected]
> Dear Svend,
>
> Thanks very much for the help.
>
> The problem is that while the file "looks" like a fixed format
> file, it is
> not fixed format...what look like demarked columns (by tabs or
> whatever) are
> actually empty blanks. Thus, running infix results in imported
> variablesthat are as below.
<snip>
*
* 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/