Your groups are defined by fundid, smallcap and year. So you want:
If you want to count only small cap firms, then
Code:
egen tag= tag(fundid smallcap year)
Code:
preserve
egen tag= tag(fundid smallcap year)
collapse (count) fundid if tag & smallcap, by(year)
sum fundid
restore
Comment