Page 1 of 1

Import .TXT into table as strings

Posted: Tue Dec 05, 2017 12:06 am
by tvonbrasch
Hi

I want to import a text file into a table object using the command

Code: Select all

   importtbl(text,name=table)  xxx.txt


However, the text for
02
is imported as
2
and
im
as
NA
(see picture below). How can this be imported direcly as a text string?

Thomas
1.PNG
1.PNG (12.39 KiB) Viewed 4261 times
2.PNG
2.PNG (11.08 KiB) Viewed 4261 times

Re: Import .TXT into table as strings

Posted: Tue Dec 05, 2017 8:50 am
by EViews Steve
You need to treat the first column as string during the import wizard.

Normally, EViews would automatically determine this, but the row that had character data in the first column was too far down the file and beyond the point in which EViews stops checking for data type.

Specifically, on page 4 of 5, you'll need to change the column data type to Character (click on the first column, then select "Character" as the Data type in the dropdown):

import wizard step 4 of 5.png
import wizard step 4 of 5.png (9.43 KiB) Viewed 4247 times

The associated captured command will also tell you how to do it programmatically:

Code: Select all

wfopen myfile.txt ftype=ascii rectype=crlf skip=0 fieldtype=delimited delim=tab types=(A,) colhead=0 eoltype=pad badfield=NA @id series01 @smpl @all

The "types=" argument is what tells EViews to treat the first column as character data.

Re: Import .TXT into table as strings

Posted: Thu Dec 07, 2017 7:14 am
by tvonbrasch
hi

thanks for your reply!

i tried your command, but it does not work.....

Code: Select all

importtbl(type=text, ftype=ascii rectype=crlf skip=0 fieldtype=delimited delim=tab types=(A,) colhead=0 eoltype=pad badfield=NA @id series01 @smpl @all)  .\lister\indeks_c_konsumaktivitet.txt


can you please take a second look at it?
Thomas

Re: Import .TXT into table as strings

Posted: Thu Dec 07, 2017 10:51 am
by EViews Steve
Oops, sorry - I forgot you were trying to create a Table instead of just a workfile.

Here's the command for importing your text file with the first column as text instead of a number:

Code: Select all

importtbl(name=mytable) Indeks_c_konsumaktivitet.txt ftype=ascii rectype=crlf skip=0 fieldtype=delimited delim=tab types=(A,) colhead=0 eoltype=pad badfield=NA

EViews created this command for me when I did the following:

1. Open a workfile
2. File menu->Import->Table from file... and selected your text file.
3. Clicked Next until I got to "Step 3 of 4" in the import table wizard.
4. Clicked on the first column (in the bottom preview) and then changed the data type to "Character" in the Data type dropdown. Click Next.
6. Entered "MyTable" as the name of the table. Click Finish.
7. Switched to the Capture window to see the generated command.

Steve

Re: Import .TXT into table as strings

Posted: Thu Dec 07, 2017 12:37 pm
by tvonbrasch
Great Steve, that worked, thanks!
Thomas