As Martin points out, there are relevant FAQs. At worst it is a loop
over observations.
Assuming that ID and PARTNER are both numeric or both string,
gen AGE_PARTNER = .
qui forval i = 1/`=_N' {
su AGE if ID == PARTNER[`i'] & SESSION == SESSION[`i'], meanonly
replace AGE_PARTNER = r(min) in `i'
}
See also
SJ-8-4 dm0043 . Tip 71: The problem of split identity, or how to group
dyads
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
J. Cox
Q4/08 SJ 8(4):588--591 (no
commands)
tip on how to handle dyadic identifiers
Nick
[email protected]
Matteo T.
I'm trying to understand how to solve a particular data mangement
problem.
I have a dataset containing groups (SESSION) of couples and singles.
Each
record within a group is made of several variables; among them: SESSION,
ID
(the unique identifier whithin each group); AGE and PARTNER. PARTNER is
either missing or is the ID of another person of the same group.
What I am trying to achieve is to create the self-explanatory variable
AGE_PARTNER.
*
* 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/