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

st: Data merge/transformation question


From   Fredrik Wallenberg <[email protected]>
To   [email protected]
Subject   st: Data merge/transformation question
Date   Thu, 28 Jul 2005 12:13:42 -0700

I have two data (Z and E) sets with a many-to-many relationship and
need some help on how to do the final stage of the merge. This is the
setup

Dataset Z
Z    E    V1
--------------
z1  e1  12
z2  e1  14
z3  e2  16


Dataset E
E    Z    V2
----------------
e1   .     6
e2   .     7
e3  z2   8

The setup ensures that there is at least one Z mapped to each E and
vice versa. Merging them I get:

z1  e1  12  6
z2  e1  14  6
z2  e3  14  8
z3  e2  16  8

Now I need to roll aggregate the observations into unique
observations. In this example I should end up with:

z3e2  16    7
zXeX  26  14

where the z3e2 is unique from the merged dataset but zXeX is a sum of
e1 and e3 as well as z1 and z2. My question to all of you is, how do I
code this last step? I can identify which Zs and Es require "rollup"
(because there are multiple obsevations). I can also identify
"overlapping rollups" (case z2 e1 above where both the Z and E in the
observation requires rollup).

While I can probably figure this out myself given some time I figure I
should see if anyone has an obvious solution.

Thanks,

Fredrik

*
*   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