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 |
Joerg Luedicke <joerg.luedicke@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: summarize, store multiple means? |

Date |
Wed, 29 Jun 2011 06:44:45 -0400 |

If you want to create a matrix by hand, you could define a matrix and then fill each cell one at a time by looping over variables and variable values. Consider the following example where the means of 10 variables are put into 10 rows and 2 columns: /**********************/ clear all set obs 100 // getting some data gen sex=runiform()>.5 forval i=1/10{ gen var`i'=rnormal() } mat t1=J(10,2,0) //Defining empty matrix forval i=0/1{ local a=1 foreach v of varlist var*{ sum `v' if sex==`i', meanonly mat t1[`a',`i'+1]=r(mean) // filling each row, one at a time loc ++a } } mat li t1 /**********************/ J. On Wed, Jun 29, 2011 at 4:09 AM, D-Ta <altruist81@gmx.de> wrote: > Good Morning, > > I would like to simply store multiple means as generated by the summarize > command: > > sum var1 var2 .. var100 > matrix averages=r(mean) > > However, only the mean of the last (var100) is stored in that matrix. Is > there anyway to store all the means or do I have to loop over all variables > and store each mean value seperately in the matrix column? > > Ultimately, I would like to run a command like: > > bys sex: sum var1 var2 .. var100 > > and store two set of means in two matrix columns, but I assume accessing > r(mean) after that command would, again, only give me the very last mean > entry. > > Cheers > > Darjusch > * > * 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/ > * * 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/

**References**:**st: summarize, store multiple means?***From:*D-Ta <altruist81@gmx.de>

- Prev by Date:
**st: Re: Two part model vs Tobit vs Heckman** - Next by Date:
**Re: st: Question about fitstat for R2** - Previous by thread:
**Re: st: summarize, store multiple means?** - Next by thread:
**st: Re: Two part model vs Tobit vs Heckman** - Index(es):