Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, 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 |
st: re: Matrix question |

Date |
Sun, 5 Feb 2012 20:11:36 -0500 |

<> I have a large mata matrix that I want to reduce: I want to replace each block of five rows with a single row containing their mean. My brute force approach goes as follows | mata: | t = mean(s[1..5 , ]) | for (i=2; i<=rows(s)/5; i++) { | t = t \ mean(s[1+(i-1)*5..5+(i-1)*5 , ]) | } | end This works, but am I missing a more efficient way of doing this, some Mata or matrix-algebra trick? Something tells me that I should be able to avoid looping here. Probably some more elegant way of generating the transformation matrix, but: mata bigmat = runiform(15,6) trans = J(1, 5, 1/5) zer = J(1,5,0) transmat = (trans, zer, zer \ zer, trans, zer \ zer, zer, trans) reduced = transmat * bigmat bigmat reduced end 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: Matrix question***From:*brendan.halpin@ul.ie (Brendan Halpin)

- Prev by Date:
**Re: st: Non integer weights - problem** - Next by Date:
**st: combining surveys** - Previous by thread:
**st: change keyboard mapping in Stata 12 for Mac** - Next by thread:
**Re: st: re: Matrix question** - Index(es):