Announcement

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

  • From file of parents to a file of brothers

    Hello.
    I have a 2 column file: parents and their children. From this I need to build another file of brothers and half brothers, in which for each child of the first file they are identified, to the side by columns, each and every one of their brothers (2 parents in common) and half brothers (only one common father). That is, fom a file like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(par child)
    1 10
    1 11
    1 12
    2 10
    2 15
    end

    ...I need to build a file like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(b1 b2 b3 b4)
    10 11 12 15
    11 10 12  .
    12 11 10  .
    15 10  .  .
    end
    How can I do it?

    Thank you

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(par child)
    1 10
    1 11
    1 12
    2 10
    2 15
    end
    
    preserve
    rename child b
    tempfile copy
    save `copy'
    restore
    
    joinby par using `copy'
    drop par
    by child (b), sort: drop if b == b[_n-1]
    by child (b), sort: drop if b == child & _N > 1
    by child (b): gen _j = _n+1
    reshape wide b, i(child) j(_j)
    rename child b1

    Comment


    • #3
      Thank you so much.
      For a small file it worked perfectly. But sadly I forgot to mention that my working file has 28 million rows. I've been gradually growing it (with 1 million rows it worked fine), but I don't think I'll ever get to 28 million, I think Stata will explode on my computer. I think I will have no choice but to look for another option...

      Comment


      • #4
        (it worked!! to my surprise... i owe you more than one coffee, thanks again!)

        Comment


        • #5
          Glad it worked. I don't know whether we'll ever meet up so that I can take you up on the coffee offer. But, should it happen, I actually drink tea, not coffee. Thanks!

          Comment

          Working...
          X