Announcement

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

  • long type data_salary differences

    [Very sorry, text version can't figure it out the exact column. Please look at the photo file. I'm so sorry.]

    I have a long type data like following;

    hid pid rel sex marriage salary
    1 101 1 1 1 300
    1 102 2 0 1 0
    2 201 1 1 1 0
    2 202 2 0 1 250
    2 203 3 1 0 0
    3 301 1 1 1 350
    3 302 2 0 1 450

    where if rel=1 then husband, rel=2 wife, rel=3 children, and if sex=1 then male, sex=0 female.
    In this case how can I get the differences between husband's and wive's salary, like following ;

    differences
    hid pid rel sex marriage salary A_type B_type C_type
    1 101 1 1 1 300 300 300
    1 102 2 0 1 0 -300 -300
    2 201 1 1 1 0 -250 -250
    2 202 2 0 1 250 250 250
    2 203 3 1 0 0 0
    3 301 1 1 1 350 -100 -100
    3 302 2 0 1 450 100 100

    The kind of types do not matter.
    Last edited by TaeWon; 25 Jan 2015, 23:55.

  • #2
    V\ery sorry, text version can't figure it out the exact column. Please look at the photo file. I'm so sorry.

    Comment


    • #3
      TaeWon,
      unfortunately, no photo file is attached to your post.
      Anyway, I would take a look at -help reshape-.
      PS: just out of curiosity, what is the meaning of *_type (*=different uppercase letters) in yuor target database?
      Kind regards,
      Carlo
      (Stata 18.0 SE)

      Comment


      • #4
        Thanks for your attention.
        Actually photo file is posted on your 'upper reply'.
        I'm sorry but I'm novice at the forum.
        If you see the photo file you can figure it out the *_type immediately.

        Kind regards, TaeWon

        Comment


        • #5
          Code:
           
          clear 
          input hid pid rel sex marriage salary
          1 101 1 1 1 300
          1 102 2 0 1 0
          2 201 1 1 1 0
          2 202 2 0 1 250
          2 203 3 1 0 0
          3 301 1 1 1 350
          3 302 2 0 1 450
          end 
          gen married = inlist(rel, 1, 2) 
          bysort hid married : gen diff = salary[3 - _n] - salary if married & _N == 2
          Technique is documented at http://www.stata-journal.com/sjpdf.h...iclenum=dm0043

          Comment


          • #6
            Thanks Nick!
            It's awesome!

            Comment

            Working...
            X