Bookmark and Share

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


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

st: Sum of products by sub-groups in mata.


From   Amadou DIALLO <[email protected]>
To   statalist <[email protected]>
Subject   st: Sum of products by sub-groups in mata.
Date   Mon, 20 Jan 2014 17:47:35 +0100

Hi,
I want to compute in mata total by subgroup (the equivalent of stata's
bys group: egen total = total(expense) ).How to do that?

Also, is it possible to use "if" condition with mata? SOmething like:

   mata:
        sum = 0
      	for (i=1; i<= maxcountry; i++) {
           sum = sum + sum(expense) if country == i
        }
    sum
   end

-- 
Amadou B. DIALLO, PhD.
Senior Economist, AfDB.
[email protected]
+21671101789
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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