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: Weighted summing in a loop for members of a group
From
Timm Klare <[email protected]>
To
[email protected]
Subject
Re: st: Weighted summing in a loop for members of a group
Date
Wed, 23 Mar 2011 19:31:49 +0100
Thank you for your answers. I know the FAQs about members of a group,
the -by-, -total- and -egen- functions but my problem lies in the
calculation in the loop over a range of values in each group. If there
are e.g. 50 group members in one of the groups, the first sum has to
be calculated as follows (example variables are X, Y & Z):
(X1 - X2)*Y2/Z + (X1 - X3)*Y3/Z + .... + (X1 - X50)*Y50/Z
and the 10th sum:
(X10 - X1)*Y1/Z + (X10 - X2)*Y2/Z + .... + (X10-X50)*Y50/Z
That's why I asked for a capital-sigma like function.
Thank you for your consideration
2011/3/23 Nick Cox <[email protected]>
>
> There is a -sum()- function and an -egen- function -total()-. But the
> twist for you appears to be the calculation w.r.t. all others in a
> group. That is an FAQ:
>
> FAQ . . Creating variables recording prop. of the other members of a group
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
> 4/05 How do I create variables summarizing for each
> individual properties of the other members of a
> group?
> http://www.stata.com/support/faqs/data/members.html
>
> Nick
>
> On Wed, Mar 23, 2011 at 5:15 PM, Timm Klare <[email protected]> wrote:
>
> > I would appreciate your help in solving the following problem. I work
> > on a dataset containing balance sheet and other information about a
> > couple of million European companies (AMADEUS). The data relevant to
> > my current problem is made up of the following variables:
> >
> > GROUP_PARENT NUM_ID YEAR TOTAL_ASSETS GROUP_TOTAL_ASSETS TAXRATE
> >
> > NUM_ID is the unique ID of each company and GROUP_PARENT is the ID of
> > the parent company for each group of companies. For each NUM_ID and
> > YEAR I need to calculate an new variable. It should sum the
> > asset-weighted tax rate differences between each NUM_ID YEAR and all
> > other companies in each group:
> >
> > (sigma sign) (TAXRATE[NUM_ID] – TAXRATE[i])*(TOTAL_ASSETS[i]/GROUP_TOTAL_ASSETS)
> >
> > Where i corresponds to all other companies in the observed group.
> > How can this be done? Is there a “sigma sign” like summing function in
> > Stata? I tried using a foreach loop but failed.
>
> *
> * 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/
*
* 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/