Generating a series w. a sort and selected sum function

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

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

ewijks
Posts: 7
Joined: Tue Nov 16, 2010 2:36 am

Generating a series w. a sort and selected sum function

Postby ewijks » Tue Nov 16, 2010 3:25 am

Dear ,

I would like to construct a concentration measure from a panel dataset (cross-section: banks, time-series: date/quarter):
I have a series providing each individual bank's market share over time.
From this I wish to construct a time series indicating the share held by the largest three (/five) banks in a given time period.

Is it possible to generate such a series (both c3 and c5) using the Genr command? What is the required syntax?

Thank you very much for your response,
kind regards,
Saskia

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Generating a series w. a sort and selected sum function

Postby EViews Glenn » Tue Nov 16, 2010 10:34 am

Do you have a fixed number of banks per period?

ewijks
Posts: 7
Joined: Tue Nov 16, 2010 2:36 am

Re: Generating a series w. a sort and selected sum function

Postby ewijks » Tue Nov 16, 2010 10:48 am

Thank you for your reply.
No, the number is not fixed.

Saskia

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Generating a series w. a sort and selected sum function

Postby EViews Glenn » Tue Nov 16, 2010 1:06 pm

Unfortunately, there's not a single line way of doing this (so far as I can determine) since we don't have a @ranksby function. Luckily, however, it's not too difficult to write a program which does this. Here is a program snippet that should do what you want to do. The idea here is that we want to create a new series equal to the original (here I use EMP) but with observations that are not in the topmost set of 3 or 5 for each period set to NA.

Then we can compute sums-by the period to get your concentration measure. The sums-by will naturally match-merge back to the original period, but you could concentrate down to a measure by period if you really want (I do this in the last part).

The code is loosely annotated, but I think it shouldn't be too hard to figure out what's going on.

Code: Select all

' number of elements to use in forming concentration measure !n = 3 ' get the period identifier series period_id = @cellid ' target series for recode series recoded_series recoded_series = na ' loop over periods recoding all but the highest !n elements in each period as NAs !high = @max(period_id) for !i=1 to !high smpl @all if period_id=!i recoded_series = @recode(@ranks(emp, "d")<=!n, emp, na) next ' compute the sums-by of the recoded series smpl @all series sums_by = @sumsby(recoded_series, period_id) ' compact by putting first observation in each period a vector smpl if cross_id = @minsby(cross_id, period_id) stom(sums_by, concentration)

ewijks
Posts: 7
Joined: Tue Nov 16, 2010 2:36 am

Re: Generating a series w. a sort and selected sum function

Postby ewijks » Wed Nov 17, 2010 8:07 am

Glenn,

Thank you very much for the code. Running the program, I've run into the following run error. I am unfortunately not experienced enough with the type of code to know how to remedy the problem:

Too many dimensions in sort in "genr recoded_series = @recode(@ranks(share, "d")<=3, share, na)"

'share' is the original series, which has a panel structure (i.e. observations ranked according to both cross-section and time series id).

Do you know what may be causing the problem and how to solve it?

Thank you for your time and effort.

Best, Saskia

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Generating a series w. a sort and selected sum function

Postby EViews Glenn » Wed Nov 17, 2010 11:53 am

I think it's something in the @ranks call for your data. Can you split the assignment into multiple lines so that the @ranks is generated into a new series on a separate line.

And if it is the @ranks, can you tell me how many observations in the workfile (cx and period), and can you tell me a bit more about the nature of the share variable? (real-valued, integer, lots-of-ties, etc.)

ewijks
Posts: 7
Joined: Tue Nov 16, 2010 2:36 am

Re: Generating a series w. a sort and selected sum function

Postby ewijks » Thu Nov 18, 2010 5:07 am

Taking the @ranks function out altogether works (the series then ranks the values 1 to 400,000 which is equal to the # of observations with a few NA's).
Running the loop for just the @ranks function results in the familiar run-error: Too many dimensions in sort in "series ranks=@ranks(share,"d")"

share is defined as follows: share=totass/@sum(totass,"1992q4 2010q2")
, in wich totass is raw data, viz. total assets as reported by banks every quarter (thus the numbers are real values/continuous)
Perhaps this variable should be constructed differently? (It should provide a bank's share of the total per period.)

The dataset structure: 1992Q4 2010Q2 x 16385 (cross-section) -- appr. 440,000 observations (the panel is unbalanced)

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Generating a series w. a sort and selected sum function

Postby EViews Glenn » Thu Nov 18, 2010 12:35 pm

I'm puzzled. I just ran an @ranks on roughly your dataset (but with 1.1 million observations) and it ran fine. What happens if you just do an @ranks outside the loop on your share variable for the whole sample? if you have problems, could you send me a copy of your workfile with just that series (support@eviews.com).

ewijks
Posts: 7
Joined: Tue Nov 16, 2010 2:36 am

Re: Generating a series w. a sort and selected sum function

Postby ewijks » Fri Nov 19, 2010 4:28 am

It appears the problem was rooted in the sample specification. I had an if statement in place, after removal the program ran as it should. Glenn, thank you very much for your help, now that the error has been resolved, it does the trick perfectly. Thanks again.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 1 guest