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]
Re: st: Sum of products by sub-groups in mata.
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Sum of products by sub-groups in mata.
Date
Mon, 20 Jan 2014 17:08:19 +0000
Mata has an -if- but nothing quite like Stata's -if- qualifier. But
neither is in general a good solution to selective summation.
: y = ("frog", "toad", "newt")
: x = (1, 2,3)
: sum(x :* (y :== "frog"))
1
See also -select()- and -panelsetup()-.
Nick
[email protected]
On 20 January 2014 16:47, Amadou DIALLO <[email protected]> wrote:
> 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/
*
* 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/