Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to tabulate only matched pairs?

    Hi,

    I would like to cross-classify test results (variable y) between test A (variable test == 1) and test B (variable test == 2), by variable d for which both test results are available. How to find the matched pairs?

    Thank you in advance!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int cid byte(ear test y d)
     1 1 1 1 0
     1 1 3 1 0
     2 1 1 0 0
     2 1 2 0 0
     2 1 3 1 0
     2 2 1 0 0
     2 2 2 0 0
     3 1 1 0 0
     3 1 3 1 0
     4 1 1 1 0
     4 1 2 1 0
     4 1 3 1 0
     4 2 1 1 0
     4 2 2 1 0
     5 1 2 1 1
     6 1 1 0 0
     6 1 2 0 0
     6 1 3 0 0
     6 2 1 0 0
     7 1 1 1 0
     7 1 2 0 0
     7 1 3 1 0
     8 1 1 1 0
     8 1 2 0 0
     8 1 3 1 0
     8 2 1 1 0
     8 2 3 1 0
     9 1 1 0 1
     9 1 2 1 1
     9 1 3 1 1
    10 1 1 0 0
    10 1 2 0 0
    10 1 3 1 0
    11 1 1 0 0
    11 1 2 0 0
    11 1 3 0 0
    11 2 1 0 0
    11 2 2 0 0
    11 2 3 0 0
    12 1 3 0 0
    13 1 1 1 1
    13 1 2 1 1
    13 1 3 0 1
    13 2 3 0 0
    14 1 1 0 0
    14 1 2 0 0
    15 1 2 1 1
    16 1 1 0 1
    16 1 2 0 1
    16 1 3 0 1
    16 2 1 0 0
    16 2 2 0 0
    16 2 3 0 0
    17 1 1 1 0
    18 1 1 0 1
    18 1 2 0 1
    18 1 3 1 1
    18 2 1 0 0
    18 2 2 1 0
    19 1 1 1 0
    19 1 3 1 0
    20 1 1 0 0
    20 1 2 0 0
    20 1 3 0 0
    21 1 2 0 0
    21 1 3 1 0
    22 1 2 1 1
    22 1 3 1 1
    23 1 3 0 1
    24 1 1 1 0
    24 1 3 1 0
    25 1 2 1 0
    25 1 3 1 0
    26 1 1 0 1
    26 1 2 0 1
    26 1 3 0 1
    26 2 2 1 1
    27 1 1 1 1
    28 1 1 1 1
    28 1 2 1 1
    28 1 3 1 1
    28 2 1 1 0
    28 2 2 1 0
    29 1 2 1 0
    30 1 1 1 1
    30 1 2 1 1
    30 1 3 1 1
    30 2 1 0 1
    30 2 3 1 1
    31 1 1 0 0
    31 1 2 0 0
    32 1 1 1 1
    32 1 2 1 1
    32 1 3 0 1
    32 2 1 1 0
    32 2 2 0 0
    32 2 3 0 0
    33 1 1 1 1
    34 1 1 0 0
    34 1 2 0 0
    end
    label values test testl
    label def testl 1 "B", modify
    label def testl 2 "A", modify
    label def testl 3 "C", modify
    label values y posneglb
    label def posneglb 0 "neg", modify
    label def posneglb 1 "pos", modify
    label values d ynlbl
    label def ynlbl 0 "no", modify
    label def ynlbl 1 "yes", modify

  • #2
    I am confused by your question. What are the criteria for deciding what is matched with what? You have lots of observations here and it isn't at all obvious what would cause you to match any of them with any of the others. You suggest that variable d has something to do with it, but it is not at all apparent in what way. Please explain, and also show us what the result would look like for the example data you posted (or for a smaller data example, but one that clearly illustrates the process.)

    Thank you for using -dataex-.

    Comment


    • #3

      Hi,

      The matching variables are cid and ear. I want to create the tables that can be created from the following commands:

      reshape wide y d, i(cid ear) j(test)
      bysort d1: tabulate y2 y1

      Is there any way that I can create the tables without changing the data to the wide format?


      Comment


      • #4
        I don't think there is any way around the -reshape wide- in order to get this. This is one of those infrequent situations where a Stata analysis requires wide layout.

        Comment

        Working...
        X