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: referencing values of others on a variable


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: referencing values of others on a variable
Date   Tue, 9 Jul 2013 11:20:58 +0200

On Tue, Jul 9, 2013 at 10:58 AM, Viktor Emonds  wrote:
> I have a file where for each student, there are as many observations as there are possible ties to other classmates (directed, based on nomination)<snip>
> I would like to compute indices of friendship segregation along ethnic lines and need to evaluate whether the ethnicities of ego and alter match or not. How to do so in Stata syntax?


I assume you have (at least) two files: one with the network and one
with individual characteristics like race. The trick is to merge these
files twice: once using the ego_id and once using the alter_id. After
that it is just a matter of comparing variables on the same
observation (in this case, pair of students):

*------------------ begin example ------------------
// create example datasets
clear

tempfile network vars

input ego alter tie
001 002 1
001 003 0
001 004 0
001 005 1
002 001 0
002 003 0
002 004 0
002 005 1
end
save `network'

drop _all
input id race
001 1
002 1
003 2
004 3
005 1
end
save `vars'

// merge the vars into network:
use `network'
rename ego id
merge m:1 id using `vars'
rename id ego
rename race ego_race
assert _merge != 1
keep if _merge == 3
drop _merge

rename alter id
merge m:1 id using `vars'
rename id alter
rename race alter_race
assert _merge != 1
keep if _merge == 3
drop _merge

// compare race ego with race alter
gen same_race = ego_race == alter_race

// admire the result
sort ego alter
list, sepby(ego)
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index