Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Count of unique cases by group


From   "Ben Hoen" <[email protected]>
To   <[email protected]>
Subject   st: Count of unique cases by group
Date   Fri, 6 Jan 2012 10:30:47 -0500

Happy New Year Statalisters!

I have been going in circles on a seemingly easy question and am hoping
someone can simplify this.

I want to count the number of unique cases within a group to generate a
summary table.  .collapse gets me part of the way there, but not all of the
way.

sysuse auto, clear
g make2=word(make,1)
rename rep78 area
keep make2 area price
keep in 1/20
drop if area==.
sort area make2
order area make2
list

Using these records, I would like to produce a table with a statistic
representing the count of the unique groups of make2 in each area, divided
by the count of make2 in each area.  

i.e. pctcount=count of groups of make2 / count of make2

So the output table would look like this ideally (minus the "underlying
calculation" column):

area	pctcount	<underlying calculation>
2	0.6666		2/3
3	0.25		4/12
4	1		2/2
5	1		1/1

Thanks, in advance, for any thought you give this.

Best,

Ben


Ben Hoen
Principal Research Associate
Lawrence Berkeley National Laboratory
Office: 845-758-1896
Cell: 718-812-7589
[email protected]
http://eetd.lbl.gov/ea/emp/staff/hoen.html



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index