Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Problems in generetaing a variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Problems in generetaing a variable
Date   Thu, 5 Feb 2009 10:41:38 -0000

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 
n.j.cox@durham.ac.uk 

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/



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