Page 1 of 1
@ngroups function
Posted: Mon Mar 15, 2010 6:28 am
by bjoern
I tried to use the „@ngroups” function in the following way.
series test_a= @groupid(lfd_nr)
scalar test_b= @ngroups(test_a)
Whereas the series test_a is generated, the scalar test_b is not. I got the following error code:
@NGROUPS is an illegal or reserved name in "SCALAR TEST_B=@NGROUPS(TEST_A)"
Could you give me an indication why it doesn’t work?
Thank you in advance for your efforts.
Re: @ngroups function
Posted: Mon Mar 15, 2010 8:25 am
by EViews Gareth
I guess this is a bug, but more of a documentation bug - that function doesn't actually exist (you'll note it is not documented in the command reference).
You can calculate it easily enough yourself though, simply by taking the max of the groupids:
series grouid = @groupid(x)
scalar ngroups = @max(groupid)
Re: @ngroups function
Posted: Mon Mar 15, 2010 1:50 pm
by bjoern
Thank you very much.
But note, this sentence is from the user's guide I (Eviews 6 (PDF: page 753, Printed Version: page 749) at the end of the section "by-group statistics":
"There are two related functions of note,
@groupid(arg[, smpl])
returns an integer indexing the group ID for each observation of the series or alpha expression
arg, while:
@ngroups(arg[, smpl])
returns a scalar indicating the number of groups (distinct values) for the series or alpha
expression arg."
Re: @ngroups function
Posted: Mon Mar 15, 2010 2:00 pm
by EViews Gareth
Hence my assertion that it is a documentation bug.
Re: @ngroups function
Posted: Mon Mar 15, 2010 2:29 pm
by bjoern
Thank you once again. In the meantime I have detected another "bug". I tried to use the @groupid function for an alpha series. Unfortunately, it doesn't work. Do you know how to get the number of distinct values for an alpha series?
Re: @ngroups function
Posted: Mon Mar 15, 2010 2:46 pm
by EViews Gareth
The only way is to do a one-way tabulation.
Re: @ngroups function
Posted: Mon Mar 15, 2010 5:06 pm
by startz
Possibly, something like
Code: Select all
group g @expand(alphaSeries)
g.@count
d g
Re: @ngroups function
Posted: Mon Mar 15, 2010 5:22 pm
by EViews Gareth
Excellent suggestion.
Re: @ngroups function
Posted: Tue Mar 16, 2010 1:27 pm
by EViews Glenn
Can I play too?
Code: Select all
alphaSeries.makemap x x_map
series groupid = @groupid(x)
scalar ngroups = @max(groupid)
delete groupid x x_map
creates a mapped numeric series out of the alphaSeries and then does Gareth's trick. Should be a bit more efficient than doing the expand.
Re: @ngroups function
Posted: Tue Mar 16, 2010 2:36 pm
by bjoern
Thank you very much! I will try your suggestions.
Re: @ngroups function
Posted: Thu Aug 05, 2010 11:52 am
by worrallj
Any advice on the best way to do something kinda like @groupid(ser1, ser2), where you are indexing the distinct values of ser1 for each value of ser2? the result might look something like:
ser1 ser2 result
1 1 1
1 3 2
1 3 2
2 5 1
2 5 1
2 20 2
2 5 1
I know I could just define a sample for each value of ser1 and do it that way, but that seems really innefficient.
Re: @ngroups function
Posted: Wed Aug 11, 2010 11:04 am
by EViews Glenn
I can't think of an easy other than your suggestion, but I'll give it some more thought.