Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Creating variables with values taken from other observations


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Creating variables with values taken from other observations
Date   Tue, 10 Aug 2010 09:13:32 -0400


I think you need to merge. Using your notation:

 preserve
 drop Rid
 ren Fid Rid
 ren Gender FGender
 keep Rid FGender
 sort Rid
 save friends, replace
 restore
 merge 1:1 using friends


hth,
Jeph


On 8/10/2010 8:36 AM, Mark McCann wrote:
Hello folks,


I've worked out a way to do this using excel, but I'd much prefer to keep everything in Stata instead of jumping back and forward every time I generate a variable along these lines.


My data has three variables

Respondent ID  -  Friend ID - Respondent Characteristic

The best friend ids all correspond to another respondent's ID.

I want to create a variable - best friend's characteristic.

For each observation I want to take that observation's friend ID, find the observation that has this friend id value as its value for respondent ID, read this observation's characteristic value and create a new variable taking the characteristic's value for the original observation.



Question again in table format because I know that description wasn't very clear


I have data like this

Rid	Fid	Gender

1	2	Female
2	5	Male
5	7	Missing
.	.	.
.	.	.


How do I create this?


Rid	Fid	Gender		Fgender

1	2	Female		Male
2	5	Male		Missing
5	7	Missing	etc.
.	.	.		.
.	.	.		.

Is there a way to do this in Stata? I used gender as a reader-friendly example however I will be using predominantly numeric coding.


	Many thanks,		
		Mark McCann


Research Statistician
Improving Children's Lives
Institute of Child Care Research
Queen's University Belfast
6 College Park
Belfast BT7 1LP

Tel: +44(0)28 9097 3163

Improvingchildrenslives.org


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

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index