Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: re: statsby, collecting betas


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: statsby, collecting betas
Date   Mon, 13 Dec 2004 22:33:38 -0500

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.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index