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
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: referencing values of others on a variable
Date
Tue, 9 Jul 2013 10:19:25 +0100
Let's look at
samerace= race==race[idstudent=idalter]
and fill in the implicit -generate- and correct the illegal = to ==
gen samerace= race==race[idstudent==idalter]
This is now legal but a long way from what you want.
The expression
idstudent==idalter
will be true (1) for observations in which idstudent == idalter and
false (0) otherwise. That means false always, presumably. So Stata
sees
gen samerace = race==race[0]
but -race[0]- is outside the range of the data and therefore evaluated
as missing. So you end with an indicator for missing race.
A strategy for your kind of data was spelled out at
http://www.stata-journal.com/sjpdf.html?articlenum=dm0043 As it is
quite detailed, I will not repeat it here.
Nick
[email protected]
On 9 July 2013 09:58, Viktor Emonds <[email protected]> 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), with the following basic structure:
>
> id student id 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
>
> 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 know you can refer to values on a variable for another observation, e.g. samevalue= var==var[_n-1], but I cannot seem to extend this to something like samerace= race==race[idstudent=idalter]. Any ideas on how I can do this?
*
* 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/