Carter:
The trick is a combination of -reshape- and -merge-. See example.
HTH,
Maarten
*---------------begin example-------------
drop _all
tempfile a
input frnd delinq
99 2
88 3
77 5
66 2
55 6
44 8
end
sort frnd
save `a', replace
drop _all
input aid frnd1 frnd2 frnd3 frnd4
99 66 77 . .
88 77 99 . .
77 55 44 99
66 88 99 44 77
55 44 . . .
44 66 . . .
end
reshape long frnd, i(aid)
drop if frnd ==.
sort frnd
merge frnd using `a'
drop if _merge == 2 /*remove people who are nobodys friend*/
drop _merge
reshape wide frnd delinq, i(aid) j(_j)
list
*---------------------end example-----------------------
--- Carter Rees <[email protected]> wrote:
> I am working with a data set in which cases are students each of which has a
> unique identifier aid. Also, for each student I have a delinquency variable
> (delinq) which is a count of the number of delinquent acts they have
> committed over the past 12 months. Each student has nominated up to 10
> friends which are represented by the variable vector frnd1-frnd10. The
> values of frnd1-frnd10 are the aid's of each of the nominated friends. What
> I would like to do is create a variable vector fr1del-fr10del which takes on
> the delinquency value for each of the nominated friends.
> aid delinq frnd1 frnd2 frnd3 frnd4 frnd5 ...
> 99 2 66 77
> 88 3 77 99
> 77 5 55 44 99
> 66 2 88 99 44 77
> 55 6 44
> 44 8 66
>
-----------------------------------------
between 1/2/2006 and 31/3/2006 I will be
visiting the UCLA, during this time the
best way to reach me is by email
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/
*
* 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/