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
Generating a series w. a sort and selected sum function
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
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
Do you have a fixed number of banks per period?
Re: Generating a series w. a sort and selected sum function
Thank you for your reply.
No, the number is not fixed.
Saskia
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
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.
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)Re: Generating a series w. a sort and selected sum function
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
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
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.)
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.)
Re: Generating a series w. a sort and selected sum function
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)
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
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).
Re: Generating a series w. a sort and selected sum function
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.
Who is online
Users browsing this forum: No registered users and 1 guest
