@ngroups 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

bjoern
Posts: 5
Joined: Mon Mar 15, 2010 6:04 am

@ngroups function

Postby bjoern » Mon Mar 15, 2010 6:28 am

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: @ngroups function

Postby EViews Gareth » Mon Mar 15, 2010 8:25 am

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)

bjoern
Posts: 5
Joined: Mon Mar 15, 2010 6:04 am

Re: @ngroups function

Postby bjoern » Mon Mar 15, 2010 1:50 pm

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."

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: @ngroups function

Postby EViews Gareth » Mon Mar 15, 2010 2:00 pm

Hence my assertion that it is a documentation bug.

bjoern
Posts: 5
Joined: Mon Mar 15, 2010 6:04 am

Re: @ngroups function

Postby bjoern » Mon Mar 15, 2010 2:29 pm

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: @ngroups function

Postby EViews Gareth » Mon Mar 15, 2010 2:46 pm

The only way is to do a one-way tabulation.

startz
Non-normality and collinearity are NOT problems!
Posts: 3797
Joined: Wed Sep 17, 2008 2:25 pm

Re: @ngroups function

Postby startz » Mon Mar 15, 2010 5:06 pm

Possibly, something like

Code: Select all

group g @expand(alphaSeries) g.@count d g

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: @ngroups function

Postby EViews Gareth » Mon Mar 15, 2010 5:22 pm

Excellent suggestion.

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

Re: @ngroups function

Postby EViews Glenn » Tue Mar 16, 2010 1:27 pm

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.

bjoern
Posts: 5
Joined: Mon Mar 15, 2010 6:04 am

Re: @ngroups function

Postby bjoern » Tue Mar 16, 2010 2:36 pm

Thank you very much! I will try your suggestions.

worrallj
Posts: 3
Joined: Fri Jan 23, 2009 3:01 pm

Re: @ngroups function

Postby worrallj » Thu Aug 05, 2010 11:52 am

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.

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

Re: @ngroups function

Postby EViews Glenn » Wed Aug 11, 2010 11:04 am

I can't think of an easy other than your suggestion, but I'll give it some more thought.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests