John reported success in tweaking his ANOVAs to generate the same
number of parameters via
levels unit, local(units)
qui foreach u of local units {
qui count if unit==`u'
if (r(N)==418) anova logcpint /*nested & interacting terms*/ if
unit==`u' ,continuous(benchdwellmin) partial regress anova
if (r(N)==418) matrix results = nullmat(results) \ e(b)
}
If there are a large number of units, it would seem like this is a lot
of conditional computation. Here is a sequence that will take the place
of the "count" and "if r(N)==418" inside the loop:
(to set up the example)
webuse grunfeld, clear
drop in 5
drop in 53
drop in 102
drop in 190
(here is the meat)
egen unitobs = count(company), by(company)
su unitobs,mean
g wantunit = (unitobs==r(max))
levels company if (wantunit), local(units)
di "`units'"
Essentially create a dummy that signals whether a unit is wanted, and
run levels only over the wanted (full run of data) units. I didn't know
that -levels- would take an if exp, but it does, and it comes in handy
here.