Announcement

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

  • Creating un-matched pair based on matched pair

    I am a new stata user, and I encountered a matching problem. Essentially I would like to convert my data from this Click image for larger version

Name:	9aa7bf341e076c0dbdf84a84be3a8d1.png
Views:	2
Size:	5.3 KB
ID:	1679867 to the following format Click image for larger version

Name:	daa09e26d256c3b886f952f66cfff52.png
Views:	2
Size:	13.1 KB
ID:	1679868. Basically, I want to add the unmatched ones based on the matched pair. Can someone help me with the code? Thank you so much in advance.
    Attached Files

  • #2
    You are new to Stata but not very new. Review FAQ Advice #12 on how to post effectively and #3 https://www.statalist.org/forums/help#adviceextras on our preference for full real names.

    Code:
    clear
    input str3 contributor float(receiver date)
    "A" 1 2000
    "B" 2 2000
    "C" 3 2000
    end
    
    fillin contributor date receiver
    g check=cond(!_fillin, "Y", "N")

    Res.:

    Code:
    . sort contributor _fillin
    
    . l, sepby(cont)
    
         +----------------------------------------------+
         | contri~r   receiver   date   _fillin   check |
         |----------------------------------------------|
      1. |        A          1   2000         0       Y |
      2. |        A          2   2000         1       N |
      3. |        A          3   2000         1       N |
         |----------------------------------------------|
      4. |        B          2   2000         0       Y |
      5. |        B          3   2000         1       N |
      6. |        B          1   2000         1       N |
         |----------------------------------------------|
      7. |        C          3   2000         0       Y |
      8. |        C          2   2000         1       N |
      9. |        C          1   2000         1       N |
         +----------------------------------------------+

    Comment


    • #3
      Thank you so much for your help.

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        You are new to Stata but not very new. Review FAQ Advice #12 on how to post effectively and #3 https://www.statalist.org/forums/help#adviceextras on our preference for full real names.

        Code:
        clear
        input str3 contributor float(receiver date)
        "A" 1 2000
        "B" 2 2000
        "C" 3 2000
        end
        
        fillin contributor date receiver
        g check=cond(!_fillin, "Y", "N")

        Res.:

        Code:
        . sort contributor _fillin
        
        . l, sepby(cont)
        
        +----------------------------------------------+
        | contri~r receiver date _fillin check |
        |----------------------------------------------|
        1. | A 1 2000 0 Y |
        2. | A 2 2000 1 N |
        3. | A 3 2000 1 N |
        |----------------------------------------------|
        4. | B 2 2000 0 Y |
        5. | B 3 2000 1 N |
        6. | B 1 2000 1 N |
        |----------------------------------------------|
        7. | C 3 2000 0 Y |
        8. | C 2 2000 1 N |
        9. | C 1 2000 1 N |
        +----------------------------------------------+
        Hi Andrew,

        Thank you so much for your post. But that filling does not sort all of my problems. Basically, I do not want all the interactions between contributors and receivers. I want to have, at each of the given dates, all interactions between each contributor to that (those) receivers. How can I achieve that? Can you help me with that?

        Thank you so much for your help.

        Comment


        • #5
          I am sorry I did not make that clear. The problem should be changing
          contributor receiver date
          A 1 2000
          B 2 2001
          C 3 2002
          to the following format
          contributor receiver date check
          A 1 2000 Y
          B 1 2000 N
          C 1 2000 N
          B 2 2001 Y
          A 2 2001 N
          C 2 2001 N
          C 3 2002 Y
          B 3 2002 N
          A 3 2002 N
          How can I achieve this?

          Comment


          • #6
            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input str1 contributor byte receiver int date
            "A" 1 2000
            "B" 2 2001
            "C" 3 2002
            end
            
            fillin receiver contributor
            bys receiver(date): replace date= date[1]
            g check= cond(!_fillin, "Y", "N")
            Res.:

            Code:
            . l, sepby(date)
            
                 +----------------------------------------------+
                 | contri~r   receiver   date   _fillin   check |
                 |----------------------------------------------|
              1. |        A          1   2000         0       Y |
              2. |        C          1   2000         1       N |
              3. |        B          1   2000         1       N |
                 |----------------------------------------------|
              4. |        B          2   2001         0       Y |
              5. |        A          2   2001         1       N |
              6. |        C          2   2001         1       N |
                 |----------------------------------------------|
              7. |        C          3   2002         0       Y |
              8. |        A          3   2002         1       N |
              9. |        B          3   2002         1       N |
                 +----------------------------------------------+
            Last edited by Andrew Musau; 31 Aug 2022, 00:48.

            Comment

            Working...
            X