Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: Assigning id's to other observations (after expanding)


From   "Ibarra-Caton, Marilyn" <marilyn.ibarra-caton@bea.gov>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Assigning id's to other observations (after expanding)
Date   Tue, 19 Apr 2011 15:40:16 -0400

Thanks Nick!!!!  


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Tuesday, April 19, 2011 1:50 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Assigning id's to other observations (after expanding)

The last two need the extra condition

... & toexpand

On Tue, Apr 19, 2011 at 6:48 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> Not sure I follow this at all, but example code:
>
> gen toexpand = id == parentid
> expand 2 if toexpand
> bysort parentid toexpand (id) : gen first = id[1] by parentid toexpand 
> (id) : gen last = id[_N] by parentid : replace first = first[1] by 
> parentid : relace last = last[1] by parentid : replace id = first if 
> _n == _N - 1 by parentid : replace id = last if _n == _N
>
>
>
> On Tue, Apr 19, 2011 at 6:24 PM, Ibarra-Caton, Marilyn 
> <marilyn.ibarra-caton@bea.gov> wrote:
>> I am having a hard time with coding to get the data as I need it.  
>> Any help would be greatly appreciated!!!
>>
>> My data looks like this:
>>      id          Parent id
>> 1.    Firm1   Firm3
>> 2.    Firm1   Firm3
>> 3.    Firm2   Firm3
>> 4.    Firm3   Firm3
>> In words what the data is telling me is that the parent id is the 
>> firm that absorbed the firm in the id column.  So in this case firm 3 
>> absorbed (merged with) firm 1 and firm 2.
>>
>> So I want the data to look like this:
>>
>> 1.    Firm1    Firm3
>> 2.    Firm1    Firm3
>> 3.    Firm2    Firm3
>>
>> 4.    Firm1    Firm3
>> 5.    Firm2    Firm3
>>
>> So basically duplicate observation 4 and assign the id of observation 
>> 1 & 2 to one of the duplicate observations and assign the id of 
>> observation 3 to the other duplicate observation.  For the 
>> observation that I am going to duplicate and assign a new id, it will 
>> always be the case that the id==parent id for this observation before 
>> any manipulation of the data.   I know that to duplicate observation 
>> 4 I can use the expand command.
>>
>

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