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: data manipulation question
From
DC <[email protected]>
To
[email protected]
Subject
Re: st: data manipulation question
Date
Wed, 11 Aug 2010 16:18:55 -0400
Hi Scott,
Yes. Thanks for all your help with this.
Regards,
Marcus
On Wed, Aug 11, 2010 at 12:45 PM, Scott Merryman
<[email protected]> wrote:
> Something like this?
>
> clear*
> input id race quarter move nn1 nn2 nn3
> 1 1 1 0 2 3 4
> 1 1 2 0 2 3 4
> 1 1 3 1 2 3 4
> 2 0 1 0 1 4 3
> 2 0 2 1 1 4 3
> 3 0 1 0 5 1 4
> 3 0 2 1 5 1 4
> 4 0 1 0 3 2 5
> 4 0 2 0 3 2 5
> 4 0 3 1 3 2 5
> 5 1 1 0 3 2 1
> 5 1 2 1 3 2 1
> end
> gen race2 = race
> replace race2 = 2 if race2 ==0
> l,sepby(id)
> tempfile foo
>
> //nn1
> sort nn1
> save `foo',replace
> keep if move >0
> keep id race2 quart
> rename id nn1
> rename race2 move_nn1
> sort nn1
> merge 1:m nn1 quarter using `foo'
> keep if _m >1
> drop _m
> replace move_nn1 = 0 if move_nn1 ==.
> sort id qua
>
> //nn2
> sort nn2
> save `foo',replace
> keep if move >0
> keep id race2 quart
> rename id nn2
> rename race2 move_nn2
> sort nn2
> merge 1:m nn2 quarter using `foo'
> keep if _m >1
> drop _m
> replace move_nn2 = 0 if move_nn2 ==.
>
>
> //nn3
> sort nn3
> save `foo',replace
> keep if move >0
> keep id race2 quart
> rename id nn3
> rename race2 move_nn3
> sort nn3
> merge 1:m nn3 quarter using `foo'
> keep if _m >1
> drop _m
> replace move_nn3 = 0 if move_nn3 ==.
> sort id qua
> order id race race2 quar move nn1 nn2 nn3 move_nn1 move_nn2 move_nn3
> l, sepby(id)
>
>
> Scott
>
>
> On Wed, Aug 11, 2010 at 10:01 AM, DC <[email protected]> wrote:
>> Hi Scott,
>>
>> Sorry if it is confusing.
>>
>> move is binary for whether unit i (id) moved or not in that particular quarter.
>> Hence, for id=1, he doesn't move in quarter 2
>>
>> What happens here is that id =1 does not move in quarter 2, so
>> therefore move = 0. However, in quarter 2
>> the first nearest neighbor (id =2) and second nearest neighbor
>> (id=3) moved and they were both of race 2. Hence,
>> I assigned the racial indicator for each nearest neighbor who moved to
>> move_nn1 and move_nn2.
>>
>> In the next quarter, quarter 3, id =1 moved. In same quarter, nearest
>> neighbor 3 moved as well and he was also of race 2.
>> hence, I assigned 2 to move_nn3 to denote that nearest neighbor 3
>> moved and they were of race 2.
>>
>> Perhaps,a better way to do it is to just assign a binary indicator for
>> whether nearest neighbor 1 and nearest neighbor 2
>> moved and put the race in a separate variable.
>>
>> Thanks for any assistance.
>>
>> Regards,
>> Marcus
>
> *
> * 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/
>
--
Marcus Casey, Ph.D.
Duke University
*
* 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/