Page 1 of 1
Creating quantile samples in paneldata
Posted: Mon Jan 28, 2019 2:46 am
by TNavyNuts
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.
Re: Creating quantile samples in paneldata
Posted: Mon Jan 28, 2019 10:50 am
by EViews Matt
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.
Re: Creating quantile samples in paneldata
Posted: Thu Feb 07, 2019 7:17 am
by mamo
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
Re: Creating quantile samples in paneldata
Posted: Thu Feb 07, 2019 11:43 am
by EViews Matt
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.
Re: Creating quantile samples in paneldata
Posted: Fri Feb 08, 2019 4:18 am
by mamo
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