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]
Re: st: RE: how to store the statistics calculated in a loop as a table?
From
Christopher Baum <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: RE: how to store the statistics calculated in a loop as a table?
Date
Wed, 7 Dec 2011 21:48:10 -0500
<>
I just tried the collapse, it is really handy, it is amazing how stata
create so powerful commend. I guess my old way of programming in VB is
very narrow and restricted.
But I still wanted to know if there is anyway that I could store the
results I calculated in the loop as a table? Do I need to use matrix
related commend?
The following is the code:
forvalues i=1990 (1)2010 {
forvalues n=1(1)6{
quietly sum EI_t if
trade_date_yearformat==`i' &FF_group_rank_0==`n'
local s_EI=r(sum)
quietly sum BE_t_1 if
trade_date_yearformat==`i' &FF_group_rank_0==`n'
local s_BE=r(sum)
local mean_EI_BE=`s_EI'/`s_BE'
}
}
How do I make stata to memorize the mean_EI_BE value that is
calculated after each loop , and at then end report all the mean_EI_BE
as a seperate table?
-------------------------------
webuse grunfeld, clear
egen quinq = cut(year), group(4) label
egen quincomp = group(quinq company), label
// quinq are time periods (quinquennia), company are units in this panel
tabstat invest kstock, by(quincomp) save
mata:
m = J(0,2,0)
for(i=1; i<=40; i++) {
m = m \ st_matrix("r(Stat"+strofreal(i)+")")
}
m = m , m[. , 1] :/ m[. , 2]
st_matrix("Result", m)
end
mat li Result
---------------------------------
You can add the row labels (which are also saved by tabstat) if you wish.
Kit
Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.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/