Statalist


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

Re: st: Problems in generetaing a variable


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   Re: st: Problems in generetaing a variable
Date   Thu, 05 Feb 2009 10:47:00 +0100

Matteo,

I think a variation on the following example should do the trick 
(modifications would need to take the session_id into account)

/*-----------------*/
clear
input id partner
1 3
2 4
3 1
4 2
5 .
6 .
end

gen age=rnormal()

list

quietly {
save all, replace

gen id_merge=partner
sort id_merge
save a, replace

use all, clear
ren age age_partner
keep id  age_partner
ren id id_merge
sort id_merge
save b, replace

use a, clear
merge id_merge using b
drop if _merge==2
drop id_merge _merge
sort id
}

list
/*-------------------*/


Best,

Antoine

Matteo T. wrote:
> Hi,
> 
> 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.
> Any suggestion? Thanks in advance for your help.
> 
> 
> -----------------------------------------------------------------------------------------------------------------------
> Send big files for free. Simple steps. No registration.
> Visit now http://www.nawelny.com
> *
> *   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/
> 


-- 
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index