Page 1 of 1
stats unique
Posted: Tue Aug 12, 2014 10:16 am
by startz
It would be nice if stats and statsby had an option to count the number of unique values. For example, I have teacher ids and I'd like to know how many teachers were in each grade.
Re: stats unique
Posted: Thu Aug 14, 2014 7:42 am
by EViews Glenn
How about
Code: Select all
series uniqueids = @sumsby(1, grade)
Re: stats unique
Posted: Thu Aug 14, 2014 7:46 am
by startz
How about
Code: Select all
series uniqueids = @sumsby(1, grade)
I think that gives me the number of observations in each grade. I want to know how many teachers are in each grade, where observations are on students and a number of students have the same teacher.
Re: stats unique
Posted: Thu Aug 14, 2014 7:46 am
by EViews Gareth
That doesn't do what he wants, I think.
You need the cross of unique vals.
Re: stats unique
Posted: Thu Aug 14, 2014 7:47 am
by EViews Glenn
Yeah. Just saw that when I reread it; was about to edit my post but you beat me to it. I was trying to think of how to do it with @uniquevals but then got distracted and when I came back it seemed so obvious :)
[edit] You should be able to get it with n-way tabulation but that requires some manual computation and doesn't link back to the obs in the workfile.
Re: stats unique
Posted: Thu Aug 14, 2014 8:48 am
by startz
In the application at hand, I have about 13,000 observations and 1,000 teachers. So I'd rather not produce a list of unique teacher ids. What I did was
Code: Select all
smpl if grade="G0"
scalar teachCount = @rows(@uniquevals(tchid))
and then repeated the code for different smpl if conditions. But an addition to stats would be nice.
Re: stats unique
Posted: Thu Aug 14, 2014 4:42 pm
by EViews Glenn
Fair enough. Just wanted to make sure you could get your work done for now. A @ranksby and related functions would similarly be useful.