Hello,
I would like to calculate shares in Mata. This is easy in Stata, but hard in Mata, and wondering if there is some trick or method that I am overlooking.
I have a set of, say, 3 stores that compete in 2 towns (not all stores compete in all towns). The sales data looks like this:
In Stata, I would type "bysort townid: egen denominator=sum(sales); gen share=sales/denominator", but there's nothing quite like egen in Mata. The closest I can come to this is "panelsum()". I can write "info=panelsetup(townid,1); panelsum(sales,info)". But then I'm left with the following data:
In order to use this result as a denominator, I need to expand this result back to being a 5x1 vector, so that it looks like this:
Any thoughts on how to achieve this last step?
Thanks!
Randy
I would like to calculate shares in Mata. This is easy in Stata, but hard in Mata, and wondering if there is some trick or method that I am overlooking.
I have a set of, say, 3 stores that compete in 2 towns (not all stores compete in all towns). The sales data looks like this:
townid | storeid | sales |
17 | 1 | 100 |
17 | 2 | 200 |
17 | 3 | 600 |
28 | 1 | 400 |
28 | 2 | 800 |
sales |
900 |
1200 |
denominator |
900 |
900 |
900 |
1200 |
1200 |
Thanks!
Randy
Comment