Page 1 of 2

How to select one entity's time series from a panel data set

Posted: Sat Apr 30, 2011 12:33 pm
by Steve06
Hi,
imagine you have a panel data set loaded into eviews that contains time series for 100 entities (i.e. 100 time series). The panel data set is in long (stacked) format. How can I SELECT or FILTER or EXTRACT only one of the firm's time seriesat a time to work with when subsequently running eviews commands? In other words, I need to be able to tell eviews "perform this estimation, but only for entity X, and then repeat for entity X+1 etc, store results etc."...
I have a background in Stata, VBA and real programming languages like C but no experience at all with eviews, so I'd appreciate any hint.

Thank you
Steve

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 1:43 pm
by EViews Gareth
In EViews you use samples to set which observations you want to deal with. In a panel you can just set the sample to be equal to which ever cross-section you want to work with. Thus if, say, your cross-sections are countries, you could do the follow:

Code: Select all

smpl if country="USA"
to work with all observations in the USA.

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 1:44 pm
by startz
Assuming there's a variable that identifies a firm, use smpl if. For example

Code: Select all

smpl if firm = 73

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 2:03 pm
by Steve06
thanks guys for the quick answer,
in the meantime, studying the user guide i figured out the equivalent steps in the Sample menu of my group, but your solution of providing commands is more versatile!
Can you point me to a good and quick tutorial about how to create a batch so that i can repeat my steps for every firm?
Steve

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 3:15 pm
by EViews Gareth

Code: Select all

for !i=1 to !numcross smpl if @crossid = !i 'do something here next
where !numcross is the number of cross-sections you have.

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 6:38 pm
by Steve06
thank you for providing a code snippet. i have to follow-up questions:
1. my cross-section identifier values are not sequental like 1,2,3,4,5... how can i loop over my (unique) cross-section id values?

2. more specifically, for each entity i would need to perform a cointegration test (johansen) and then have a VECM estimation under some constraints.
If you somebody posted a code example about how to call the appropriate functions, plus, more importantly, how to retrieve specific results and write them to text file, i would be more than happy.

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 10:41 pm
by tchaithonov
For 1), make good use of the function @ crossid. It ignores your numbering of the cross section and use the generic one, so it becomes 1,2,3...

Re: How to select one entity's time series from a panel data

Posted: Sat Apr 30, 2011 10:58 pm
by Steve06
thanks for joining my thread, but can you elaborate more how i make @crossid work for me in iterating over all unique identifier values?
i understood @crossid such that it just stands for whatever the variable name of my dataset is.

Re: How to select one entity's time series from a panel data

Posted: Sun May 01, 2011 7:12 am
by startz
@crossid ia a built-in function that gives a sequential numbering of cross sections in a panel data set.

Re: How to select one entity's time series from a panel data

Posted: Sun May 01, 2011 8:45 am
by Steve06
so i have to think of it as a pointer that magically moves on to the next unique id value after being used?
I looked it up in the docs but they aren't very precise: "@crossid observations in range, returns the cross-section identifier index."
but how would i know the number of unique id values in the first place, so as to have an upper boundary in constructing a loop?

Re: How to select one entity's time series from a panel data

Posted: Sun May 01, 2011 12:33 pm
by EViews Gareth
It isn't a pointer at all. Rather it is an index of the cross-sections. Type "show @crossid" to see it.

Assuming you don't already know the number of cross-sections, and since @crossid is an index of all cross-sections running from 1 to the number of cross-sections you have, a simple way to find the number of cross-sections is to take the maximum of @crossid.

Re: How to select one entity's time series from a panel data

Posted: Sun May 01, 2011 12:48 pm
by Steve06
ok, and how would i get the maximum? i tried max(@crossid) but with no luck

How to select one entity's time series from a panel data set

Posted: Sun May 01, 2011 1:57 pm
by EViews Gareth
!ncross=@max(@crossid)

Re: How to select one entity's time series from a panel data

Posted: Sun May 01, 2011 7:17 pm
by Steve06
this yields an error: "@crossid is an illegal or reserved name in !ncross=@max(@crossid)"

Re: How to select one entity's time series from a panel data

Posted: Sun May 01, 2011 8:12 pm
by EViews Gareth
That's what I get for answering without thinking...

Code: Select all

series temp = @crossid !ncross = @max(temp) d temp