Creating quantile samples in paneldata

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

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

TNavyNuts
Posts: 1
Joined: Fri Jan 25, 2019 8:10 am

Creating quantile samples in paneldata

Postby TNavyNuts » Mon Jan 28, 2019 2:46 am

Hi all, I hope you can help me.

I have constructed panel data om which i have monthly returns (x) for 500+funds, for which I will be doing three factor regression (y,z) to estimate the constant.

Now I also have monthly data on a fourth variable (u). I want to create samples (quintiles) and attribute each cross section (fund) to a quintile based upon the average value of u over the entire period (10 years).

I could go back to excel and calculate the quintiles and work with dummies, but I would assume there is a much easier way to do this in eviews.

Thanks already for your help.

EViews Matt
EViews Developer
Posts: 364
Joined: Thu Apr 25, 2013 7:48 pm

Re: Creating quantile samples in paneldata

Postby EViews Matt » Mon Jan 28, 2019 10:50 am

Hello,

I believe you can accomplish what you want with the following:

Code: Select all

for !i = 1 to 5
   sample quintile!i if (!i = 1 or @meansby(u, fund) >= @quantile(@meansby(u, fund), .2 * (!i - 1))) and (!i = 5 or @meansby(u, fund) < @quantile(@meansby(u, fund), .2 * !i))
next

where "fund" is your fund/cross-section series.

mamo
Posts: 122
Joined: Wed Nov 07, 2012 9:11 am

Re: Creating quantile samples in paneldata

Postby mamo » Thu Feb 07, 2019 7:17 am

Hi,
you may try the following, obtaining the dummy series du

Code: Select all

series du=@ceiling(@groupid(@ranks(@meansby(u,crossid, "@all"),a,l))/4)

Alternatively, assuming that there are no NA's in the @last period:

Code: Select all

dv=1
for !i=1 to 4
   series dv=dv+(@meansby(u,fund, "@all")>=@quantile(@meansby(u,fund,"@all"),(!i)*0.2,"@last @last"))
next

with du=dv

Best, mamo

EViews Matt
EViews Developer
Posts: 364
Joined: Thu Apr 25, 2013 7:48 pm

Re: Creating quantile samples in paneldata

Postby EViews Matt » Thu Feb 07, 2019 11:43 am

Clever, but the division by four isn't quite right in the first example. I believe it should be:

Code: Select all

series du=@ceiling(@groupid(@ranks(@meansby(u,fund)))/(@max(@crossid)/5))

Wasn't aware that @groupid preserved relative magnitude. That's more convenient than having to divide by @obsby(fund,fund) or equivalent.

mamo
Posts: 122
Joined: Wed Nov 07, 2012 9:11 am

Re: Creating quantile samples in paneldata

Postby mamo » Fri Feb 08, 2019 4:18 am

You are right, and honestly, after second thoughts, the first suggestion does not work at all.

If anything, the divisor should be sth like @ceiling([number of crosssections]/[number of quantile].

But even that would not in general provide the desired result.

The reason is that the actual values of the series, rather than just the ranking, is required in order to determine the quantile limits precisely.

The 2nd suggestion, i.e. the for loop, which is similar to your proposal, should work (of course, provided that there are no NA in @last).

Best, mamo


Return to “Data Manipulation”

Who is online

Users browsing this forum: Google [Bot] and 3 guests