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]

st: implementing an equivalent of egen mean() in Mata.

From   Christophe Kolodziejczyk <[email protected]>
To   [email protected]
Subject   st: implementing an equivalent of egen mean() in Mata.
Date   Thu, 1 Sep 2011 14:37:15 +0200

Dear Stata list members

I want to implement a mata function wich computes group averages over
the columns of a matrix. In other words I want to implement in Mata an
equivalent of egen with mean().
I have not been able to find such a function in the mata manual.

I have written the following function by using panelsetup(). But
because of the loop over the observations it tends to be slow with
large samples. Any idea how to make it work faster? Any other
suggestions to the code is also welcome.
Thanks for your help

real matrix meani(real vector id, real matrix x)

    real vector info, xi, meanix
    real scalar ninfo, i



    for (i=1;i<=ninfo;i++) {
        xi = panelsubmatrix(x, i, info)

*   For searches and help try:

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