Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[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 <>
To   "" <>
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
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)
mat li Result
You can add the row labels (which are also saved by tabstat) if you wish.


Kit Baum   |   Boston College Economics & DIW Berlin   |
                             An Introduction to Stata Programming  |
  An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index