Putting together several lessons from today's Statalist:
----begin code----
capture matrix drop results
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)
}
mat list results
mat2txt, matrix(results) saving(betaresults) replace
----end code----
Instead of pre-filtering my dataset I realized an inline -if- statement
that evaluates the unit to be processed would be more efficient. This
is in addition to the other version of if that restricts the anova to
the unit defined by the foreach loop. Building a matrix like this one
results in a persistent construct that needs to be erased before a new
iteration of the do-file can be run (hence the -matrix drop- command).
Finally, the mat2txt provides a handy way to save the results.
Thanks to Kit and Nick for their expertise!
-JW
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Wallace, John
Sent: Monday, December 13, 2004 12:34 PM
To: [email protected]
Subject: st: RE: re statsby: collecting betas
The difference was the -if- statement. When I revised the code to...
----begin code----
levels unit, local(units)
qui foreach u of local units {
anova logcpint /*nested & interacting terms*/ if unit==`u'
,continuous(benchdwellmin) partial regress anova
matrix results = nullmat(results) \ e(b)
}
mat list results
---end code---
...I got a new problem, that Nick alluded to in his last reply: error
505 conformibility error. For some reason it looks like the anova for
the unit following the first one ends up with a different size matrix
for e(b). When I set trace on the first unit is processed correctly,
then at the point in the next pass through where the new e(b) vectors
are joined the conformibility error occurs.
Stepping manually through the code I get
Unit 1020 e(b)[1,96]
Unit 1021 e(b)[1,104]
Unit 1021 e(b)[1,104]
...
Unit 1045 e(b){1,24]
I suspect if I do some upstream filtering of my data, so only those
units with identical terms for the independent variables in the anova
are processed I'll be successful. Thanks for your help!
-JW
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kit Baum
Sent: Monday, December 13, 2004 12:01 PM
To: [email protected]
Subject: st: re statsby: collecting betas
webuse grunfeld,clear
forv i=1/10 {
qui reg invest mvalue kstock if company==`i'
mat results = nullmat(results) \ e(b)
}
mat list results
seems to work fine in assembling these results from each firm.
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/
*
* 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/
*
* 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/