Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Christopher Baum <kit.baum@bc.edu> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

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/

**Follow-Ups**:**Re: st: RE: how to store the statistics calculated in a loop as a table?***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: logistic regression complex samples** - Next by Date:
**Re: st: logistic regression complex samples** - Previous by thread:
**st: Checking if one variable = any of the values of another** - Next by thread:
**Re: st: RE: how to store the statistics calculated in a loop as a table?** - Index(es):