How to enter data into a panel workfile.

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Moderator, EViews Gareth

How to enter data into a panel workfile.

Postby EViews Gareth on Fri Oct 10, 2008 9:39 am

There are a number of different ways to enter data into a panel workfile. Which method works best really depends upon how your data starts out.

In this post I'm going to describe a method which converts data that is currently in "pool" form into a panel. The workfile I'm using can be found at:

http://www.eviews.com/Forum_support/poo ... poolg7.wf1

The workfile looks like this:
Image

As you can see there are 7 cross-sections, CAN, FRA, GER, ITA, JPN, UK, USA, with 43 years of data (1950 to 1992) and two data series, GDP and Unemp.

Moving this data into a panel workfile is relatively simple. Via the menus you can do this:

Click on Proc->Reshape Current Page->Stack in New Page
Image

Enter the stacking identifiers.
You have a number of choices for this. The easiest, in this case, is to enter a series pattern. In our case our series (gdp and unemp) have a pattern of series_crossid. Thus I can use one of my series as a pattern. In this case I used unemp? The "?" represents the cross-section identifier (in this case _US or _CAN).
Image

Hit ok, and you're done!
Image

Note how you now have a panel workfile (you can tell from the Range statement at the top of the workfile - the fact it has a x7 at the end lets us know it is a panel).


Note if you wanted to do this via the command line, you just need to do this:
Code: Select all
pagestack unemp?


Simple!
EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
 
Posts: 1892
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to enter data into a panel workfile.

Postby EViews Gareth on Fri Oct 10, 2008 10:50 am

If your data is currently in Excel and you want to put it into a panel workfile, then, again, the best way to do it really depends upon what form the data is in inside Excel.

However here is one example.

A common form of panel data structure in Excel is the following:
Image

Note you can get this Excel file here.

Reading this sort of file into an EViews panel is easy. First open the file directly into EViews:

File->Open->Foreign Data as Workfile

Image

Select the Excel file and hit Open

Image

Check everything looks ok on the preview, and hit Finish

Image

If you're using EViews 7, you're now done (since EViews 7 will automatically recognise this data as a panel)!

If you're using EViews 6 you will now have an unstructured workfile with all of the data:
Image
And all that's left is to structure it as a panel:
Hit Proc->Structure/Resize Current Page
Change the Workfile structure to "Dated Panel"
Enter Country as Cross section ID
Enter Year as Date series


Image

And you're done!

Image

Note all of that could be done via the command line with the following:
Code: Select all
wfopen http://www.eviews.com/Forum_support/Excel2panel/byyear.xls
pagestruct country @date(year)

(note the last line is not required in EViews 7)
EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
 
Posts: 1892
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to enter data into a panel workfile.

Postby EViews Gareth on Mon Feb 02, 2009 1:12 pm

A second type of format that is used in Excel, is where the columns represent dates, then the rows represent both cross-sections and variables. Such is the case in the following:
Image

This file can be obtain from here.

This sort of structure is a little more tricky, and takes a bit more effort inside EViews. If you bring the file in by opening it into EViews, you will get a workfile that looks like this:
Image

The first thing we need to do is to stack this into a new page:
Image
Image
Notice that we use yr? as the stacking identifier since the series in EViews are all named yrXXXX.

The stack results in the following workfile page:
Image

Now we need to unstack this page into a panel. First, though, we need to change our "Variable" series a little. This is because the text inside that variable contains spaces, and we want to create new series from this text, but series names cannot contain spaces. Thus we type the following in the command pane to create a new alpha series containing valid names:
Code: Select all
alpha var2=@replace(variable," ","_")
show var2
d variable


Image

Once this new alpha series has been created, we can do the unstack:

Image
Image
Image

Now we're pretty much done. We just need to type a few more commands to tidy things up a bit (delete some un-needed series and rename some):
Code: Select all
d id02*
d yr
rename yr* *

Image

And we're done!
EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
 
Posts: 1892
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to enter data into a panel workfile.

Postby EViews Gareth on Fri Jan 08, 2010 3:04 pm

A third Excel data format is where each cross-section has its own sheet inside the Excel file, such as the one below (note each sheet represents a different country's data):
Image

Note the Excel file can be downloaded from here.

Currently EViews does not support any easy way to bring such a file into EViews. However a relatively simple EViews 7 program can be used to do the job. Such a program is outlined below. Note this program assumes (and requires) that the names of the sheets in Excel correspond to the names of the cross-sections:
Code: Select all
%filename = "c:\temp\sheetpanel.xlsx"   'file name of the file to be opened

%sheetnames = @tablenames(%filename)   'find the names of the sheets in that file

%sheetname = @word(%sheetnames,1)   'get the first sheet name

wfopen(wf=panel) %filename range=%sheetname    'open the first sheet as a new workfile (with name=panel, and pagename=the first sheet name)

alpha crossid = %sheetname   'create a cross-section identifier series, and set it equal to the sheetname

'loop through the remaining sheets, loading them into the workfile one at a time
for !i=2 to @wcount(%sheetnames)
   %sheetname = @word(%sheetnames,!i)  'get the name of the next sheet
   import %filename range=%sheetname @append  @genr crossid=%sheetname   'append the next sheet to the bottom of our workfile
next

pagestruct @date(year) crossid   'structure the page as a panel, by stating that the series "YEAR" is a date id and the series "CROSSID" is a cross-section identifier.


Note the first line of the program specifies the name of the Excel file. You should change that line to match the location of your own Excel file. The program first of all finds the names of the sheets in the Excel file, then opens up the first sheet as a new EViews workfile. It then loops through the remaining sheets, one at a time, appending them to the created workfile. Each time a sheet is brought into EViews, the alpha-series "country" is set equal to the name of the sheet, thus building up a cross-section identifier series.

Once all the sheets have been brought in, the pagestruct command is used to structure the page as a panel:
Image
EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
 
Posts: 1892
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to enter data into a panel workfile.

Postby vvel812 on Thu Jul 29, 2010 3:45 am

Hi Gareth,

I have tried following your advice on how to input data from excel into eviews, specifically your third example where each excel sheet represents a different country. I have typed the program you posted into the command window, however, I get an error message that "CROSSID is not defined".
I would very much appreciate your help on this. I am attaching my file as an example.
Many thanks in advance!
Attachments
trial.xlx.xls
The observations represent various bonds (the number is a unique code that identifies each bond) for the 2 countries.
(92 KiB) Downloaded 16 times
vvel812
 
Posts: 1
Joined: Thu Jul 29, 2010 3:20 am

Re: How to enter data into a panel workfile.

Postby EViews Gareth on Thu Jul 29, 2010 7:35 am

You need to put it in an EViews program (File->New->Program), not from the command line.
EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
 
Posts: 1892
Joined: Tue Sep 16, 2008 5:38 pm


Return to General Information and Tips and Tricks

Who is online

Users browsing this forum: No registered users and 1 guest