Import .TXT into table as strings

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Jason, EViews Moderator, EViews Pamela

tvonbrasch
Posts: 297
Joined: Fri Apr 15, 2011 5:35 am

Import .TXT into table as strings

Postby tvonbrasch » Tue Dec 05, 2017 12:06 am

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 102 times
2.PNG
2.PNG (11.08 KiB) Viewed 102 times

EViews Steve
EViews Developer
Posts: 448
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Import .TXT into table as strings

Postby EViews Steve » Tue Dec 05, 2017 8:50 am

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 88 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.

tvonbrasch
Posts: 297
Joined: Fri Apr 15, 2011 5:35 am

Re: Import .TXT into table as strings

Postby tvonbrasch » Thu Dec 07, 2017 7:14 am

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
Attachments
Indeks_c_konsumaktivitet.txt
(471 Bytes) Downloaded 3 times

EViews Steve
EViews Developer
Posts: 448
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Import .TXT into table as strings

Postby EViews Steve » Thu Dec 07, 2017 10:51 am

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

tvonbrasch
Posts: 297
Joined: Fri Apr 15, 2011 5:35 am

Re: Import .TXT into table as strings

Postby tvonbrasch » Thu Dec 07, 2017 12:37 pm

Great Steve, that worked, thanks!
Thomas


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 4 guests