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: Creating variables from a matched pair


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Creating variables from a matched pair
Date   Mon, 8 Oct 2012 20:04:54 +0100

I agree with David. This will end up a -reshape wide-. You will need
to split up your IDs. Here is some technique:

. clear

. input str4 id

            id
  1. 1A01
  2. 1B01
  3. 1A02
  4. 1B02
  5. 2A01
  6. 2B01
  7. 2A02
  8. 2B02
  9. end

. gen AB = cond(strpos(id, "A"), "A", cond(strpos(id, "B"), "B", "???"))

. gen ID = subinstr(id, "A", " ", 1)

. replace ID = subinstr(ID, "B", " ", 1)
(4 real changes made)

. split ID
variables created as string:
ID1  ID2

. l

     +------------------------------+
     |   id   AB     ID   ID1   ID2 |
     |------------------------------|
  1. | 1A01    A   1 01     1    01 |
  2. | 1B01    B   1 01     1    01 |
  3. | 1A02    A   1 02     1    02 |
  4. | 1B02    B   1 02     1    02 |
  5. | 2A01    A   2 01     2    01 |
     |------------------------------|
  6. | 2B01    B   2 01     2    01 |
  7. | 2A02    A   2 02     2    02 |
  8. | 2B02    B   2 02     2    02 |
     +------------------------------+

The splitting assumes that it really should be "A" or "B" in the
middle (and that flagging anything else will be helpful), but
otherwise assumes nothing about what's on either side (some of the
numbers might get quite big).

See also, if only as something that might come in useful:

SJ-8-4  dm0043  . Tip 71: The problem of split identity, or how to group dyads
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/08   SJ 8(4):588--591                                 (no commands)
        tip on how to handle dyadic identifiers

accessible at http://www.stata-journal.com/sjpdf.html?articlenum=dm0043

On Mon, Oct 8, 2012 at 7:33 PM, David Kantor <[email protected]> wrote:
> At 02:15 PM 10/8/2012, Jessica Kopsic wrote:
>
>> I have a dataset with matched pairs, and I'd like to create a dataset
>> where each person's partner's observations are variables.  So like this:
>> Partner A: DOB Partner A, DOB Partner B, Sex Partner A, Sex Partner B
>>
>> Currently everything is in this format:
>> Partner A: DOB Partner A, Sex Partner A
>> Partner B: DOB Partner B, Sex Partner B
>>
>> The ID numbers are structured like this:
>> 1A01
>> 1B01
>> 1A02
>> 1B02
>> 2A01
>> 2B01
>> 2A02
>> 2B02
>> The numbers at the beginning are rounds. Then partner A or B. Then numbers
>> that match the pair together. The number sets got reused for each round so
>> numbers may or may not be unique throughout the whole dataset, but they are
>> restricted to one set of partners for each round. (So IDs are unique
>> throughout the whole dataset.)
>>
>> This dataset will be used in other programs, so I'd like to create the
>> dataset up front rather than match during analyses. I'm flummoxed by this
>> one and came up empty searching archives. Thank you.
>
>
> You need to be a bit more specific about what the data look like and what
> the desired result looks like. But from a brief look, this may be a case for
> -reshape wide-.
> -reshape wide- will yield one observation for each pair. If you want two
> observations for each pair -- the second one with the roles reversed -- then
> you need to do some additional work, but it is not hard.
> Tell us more, and we'll be better able to help.
*
*   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