Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: importing "irregular" columns with embedded blanks


From   "Dr. Buzz Burhans" <[email protected]>
To   <[email protected]>
Subject   RE: st: importing "irregular" columns with embedded blanks
Date   Wed, 24 Jan 2007 07:07:00 -0500

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 variables
that are as below.  To make it more clear, I reran your infix statement with
the num1 and num2 variables coming in as strings...it shows better what the
Stata sees - or more importantly, fails to see: the embedded blanks.

Is there a way to deal with those blanks, even if I had to import each
observation as a single txt line first and then convert them?

Using Svend's statement:

clear
infix str v1 1-4 num1 5-9 str name1 11-31 str sprice 32-38 ///
   num2 39-45 str name2 50-64 str name3 68-69 using buzz.txt

I get this in the first three variables:

v1	num1	name1
ANY	1206	Bunk1 Corn Silage
123		1 Grass Hay
158		h1 Straw
123		1 Haylage 1st cut
123		4 Haylage 2nd cut
107		GrainGrndFine
039		yByProdBread
105		PulpPlCp
102		gyBooster
00"		

Running Svend's infix statement with all variables in as strings I get this
in the first 5 variables

clear
infix str v1 1-4 str num1 5-9 str name1 11-31 str sprice 32-38 ///
   num2 39-45 str name2 50-64 str name3 68-69 using buzz.txt


v1	num1	name1	sprice
ANY	1206	Bunk1 Corn Silage	
123	4 She	1 Grass Hay	$0.
158	2 Pur	h1 Straw	$0.
123	7 Sho	1 Haylage 1st cut	$0.
123	8 Bun	4 Haylage 2nd cut	$0.
107	0 Cor	GrainGrndFine	$135.
039	Bake	yByProdBread	$130.0
105	2 Bee	PulpPlCp	$140.
102	2 Ene	gyBooster	$1,20
00"			




Svend's approach was:

This looks like fixed format data; use -infix- to read it. I first
created a text file (buzz.txt) from your list:

 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

The command goes like this:

clear
infix str v1 1-4 num1 5-9 str name1 11-31 str sprice 32-38 ///
   num2 39-45 str name2 50-64 str name3 68-69 using buzz.txt

// remove $ and , from price and make it numeric
replace sprice = subinstr(sprice,"$","",.)
replace sprice = subinstr(sprice,",","",.)
generate price = real(sprice)
format price %8.2f


Hope this helps
Svend
__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________ 

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


Buzz Burhans, Ph.D.

Dairy-Tech Group
Phone: 802-755-6842
Cell: 802-388-7214 

Email: [email protected]

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