Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: aggregate identical observations


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: aggregate identical observations
Date   Fri, 12 Dec 2003 13:01:11 -0000

Alternatively, this looks like a -collapse-
or even a -contract-.

Nick
[email protected]

Ulrich Kohler

> How about:
>
> by pref1 pref2, sort: replace wgt = sum(wgt)
> by pref1 pref2: keep if _n == _N

Dietrich Dr�ner

> > I need to aggregate the number of observations in my data
> set when they
> > have identical values on two variables AND I need to sum
> up the values of a
> > third variable so that it remains the same for the
> reduced data set. I will
> > try to illustrate this and also describe the substantial problem:
> >
> > my initial data matrix looks like this:
> >
> > act	wgt	pref1	pref2
> > 1	4	100	0
> > 2	5	33	0
> > 3	3	33	50
> > 4	3	100	50
> > 5	10	33	0
> > 6	10	33	100
> > 7	5	33	50
> > 8	3	33	50
> > 9	10	33	50
> > 10	2	33	50
> > 11	5	33	0
> > 12	5	33	50
> > 13	8	33	50
> > 14	4	100	0
> > 15	10	33	50
> > 16		100	70
> > 17		100	70
> >
> > sum	87
> >
> > The first variable is the number of my actors (the 15 EU
> member states plus
> > the European Commission and the European Parliament). The
> second variable
> > is the voting weights of the member states. The third and
> fourth variables
> > are preferences of the actors in two dimensions. Many of
> the actors have
> > identical preference profiles that I need to aggregate.
> >
> > The result of this aggregation should look like this:
> >
> > act	wgt	pref1 pref2
> > 1	8	100	0
> > 2	20	33	0
> > 3	46	33	50
> > 4	3	100	50
> > 5	10	33	100
> > 6		100	70
> >
> > sum	87
> >

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index