|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Reshape, Duplicate Observations
Hi Tirthankar,
Thanks for the reply. However, this is not the one I need. Basically, for
each observation I need hid date their corresponding nids and those nid's
all possible dates. If you look at my table 3 you will understand what
exactly I want. In your solution what I am getting is that each row
incorporates within group hid dates only.
Thanks.
Arnab
> <>
> Is this perhaps what you want?
> ***************************************
> clear*
> input str2 hid str15 date fd
> A "01/03/2005" 0
> A "04/05/2006" 1
> B "02/03/1999" 1
> B "09/07/2004" 1
> B "09/07/2004" 0
> C "05/02/2004" 0
> C "03/11/2004" 1
> D "05/08/1998" 0
> end
> save 1, replace
> ******************
>
> bys hid: g j=_n
> reshape wide date fd, i(hid) j(j)
> save 2, replace
> clear
> ******************
>
> input str2 hid str2 nid1 dist1 str2 nid2 dist2
> A B .75 C .25
> B D .35 A .75
> C E .65 A .25
> D B .35 "" .
> end
> save 3, replace
> ******************
>
> use 1
> joinby hid using 2
> joinby hid using 3
> list, clean
> ***************************************
>
>
> On Sat, Aug 22, 2009 at 1:05 AM, <[email protected]> wrote:
>> I have a dataset with multiple observations (both unique and duplicate)
>> for each identifier HID. Here is an example
>>
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Table 1
>>
>> Â Â Â Â HID Â Â DATE Â Â Â FD
>>
>> Â 1. Â Â A Â 01/03/2005 Â Â 0
>> Â 2. Â Â A Â 04/05/2006 Â Â 1
>> Â 3. Â Â B Â 02/03/1999 Â Â 0
>> Â 4. Â Â B Â 09/07/2004 Â Â 1
>> Â 5. Â Â B Â 09/07/2004 Â Â 0
>> Â 6. Â Â C Â 05/02/2004 Â Â 0
>> Â 7. Â Â C Â 03/11/2004 Â Â 1
>> Â 8. Â Â D Â 05/08/1998 Â Â 0
>>
>>
>> I have another dataset (already reshaped widely) as follows
>>
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Table 2
>>
>> Â Â Â HID Â Â NID1 Â DIST1 Â NID2 Â DIST2
>>
>> 1. Â Â Â A Â Â Â B Â Â .75 Â Â Â C Â Â .25
>> 2. Â Â Â B Â Â Â D Â Â .35 Â Â Â A Â Â .75
>> 3. Â Â Â C Â Â Â E Â Â .65 Â Â Â A Â Â .25
>> 4. Â Â Â D Â Â Â B Â Â .35 Â Â Â Â Â Â Â .
>>
>>
>> Now, I want to gather information by HID on a set of other variables
>> DATE
>> and FD so that each observation in Table 2 contains information on HID
>> DATE NID* and their corresponding dates, DIST* and FD*. I am not allowed
>> to drop the duplicate observation (obs. 4 & 5) since each of them
>> contains
>> important information. The outcome table that I am looking for is as
>> follows
>>
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Table
>> 3
>>
>> Â HID Â Â DATE Â Â FD NID1 DIST1 DATE1 Â Â DATE2 Â DATE3 Â Â FD1
>> FD2 FD3 NID2
>> DIST2 DATE* FD*
>>
>> Â 1. Â A Â 01/03/05 Â 0 Â B Â .75 02/03/99 09/07/04 09/07/04 Â 0 Â
>> Â 1 Â 0
>> C Â .25
>> Â 2. Â A Â 04/05/06 Â 1 Â B Â .75 02/03/99 09/07/04 09/07/04 Â 0 Â
>> Â 1 Â 0
>> C Â .25
>> Â 3. Â B Â 02/03/99 Â 0 Â D
>> Â 4. Â B Â 09/07/04 Â 1 Â D
>> Â 5. Â B Â 09/07/04 Â 0 Â D
>> Â 6. Â C Â 05/02/04 Â 0 Â E
>> Â 7. Â C Â 03/11/04 Â 1 Â E
>> Â 8. Â D Â 05/08/98 Â 0 Â B
>>
>> Basically, my plan is to know for each group (obs.) of HID and DATE the
>> corresponding NIDS which are within a year from the DATE and their
>> corresponding total number of FDs. Thatâ??s why I think I need to go
>> through
>> Table 3.
>>
>> Thanks in advance.
>>
>> *
>> * Â 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/
>>
>
>
>
> --
> To every Ï?-consistent recursive class κ of formulae there correspond
> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
> belongs to Flg(κ) (where v is the free variable of r).
>
> *
> * 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/