Announcement

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

  • Compare values across rows within observation

    Hi,
    My datasets are like following forms:
    Inventorid patentyear firmid
    3930988 2000 13928
    3930988 2001 13928
    3930988 2002 15892
    3890212 2001 15892
    3890212 2001 15892

    I'm trying to compare firmid for the same inventor and generate a variable move = 1 if firmid != firmid in the previous rows. The desired results is as follows. For example, for inventor 3930988, he is regarded as move = 1 when the firmid change (15892 VS 13928).
    NOTE that, comparison of the firms only within observations. For example, for inventor 3930988, compare firmid within the first 3 rows. for Inventor 3890212, compare within the last two rows. Many thanks if you could provide any suggestions!

    Inventorid patentyear firmid move
    3930988 2000 13928 0
    3930988 2001 13928 0
    3930988 2002 15892 1
    3890212 2001 15892 0
    3890212 2001 15892 0


  • #2
    How would you want your move variable to be in this case?

    Inventorid patentyear firmid
    3930988 2000 13928
    3930988 2001 13928
    3930988 2002 15892
    3930988 2003 13928

    Comment


    • #3
      Originally posted by Wouter Wakker View Post
      How would you want your move variable to be in this case?

      Inventorid patentyear firmid
      3930988 2000 13928
      3930988 2001 13928
      3930988 2002 15892
      3930988 2003 13928
      Hi Wouter,
      I would like use to identify inventor who change his job. If move = 1, it implies that inventor patent in two different firms within the same year or across years. Therefore, it is implied that this inventor change his job (move to another company). Ultimately, I will extract the following information for inventors who move:

      Inventorid year firmid_before_move firmid_after_move
      3930988 2002 13928 15982

      Comment


      • #4
        Yes, I got that from #1.

        My point is, what happens when an inventor moves back to a firm where he was previously, before moving to another firm. (see #2) Do you still want to code it as being a job change? If so, or if this doesn't happen at all:
        Code:
        bysort Inventorid (patentyear): gen wanted = firmid != firmid[_n-1] & _n > 1

        Comment


        • #5
          Originally posted by Wouter Wakker View Post
          Yes, I got that from #1.

          My point is, what happens when an inventor moves back to a firm where he was previously, before moving to another firm. (see #2) Do you still want to code it as being a job change? If so, or if this doesn't happen at all:
          Code:
          bysort Inventorid (patentyear): gen wanted = firmid != firmid[_n-1] & _n > 1
          Hi Wouter,
          Many thanks for your kind help! It works quite well. For those who move back to the orignal firm, yes they are coded as a job change. And I infer that the code also code as they change a job when move back to orignal firm. Thanks pretty much!

          Comment


          • #6
            Originally posted by Wouter Wakker View Post
            Yes, I got that from #1.

            My point is, what happens when an inventor moves back to a firm where he was previously, before moving to another firm. (see #2) Do you still want to code it as being a job change? If so, or if this doesn't happen at all:
            Code:
            bysort Inventorid (patentyear): gen wanted = firmid != firmid[_n-1] & _n > 1
            By the way, if the rule changes, say, the event that inventor moves back to the orignal firm will not be refered as a mobility event. How will the code change?

            I have thought about this one, but not hundred percent sure:
            forvalues i = 1/50 {
            bysort Inventorid (patentyear): gen wanted = firmid != firmid[_n-'i'] & _n > 1
            }

            Last edited by LI LIU; 24 Jun 2020, 11:32.

            Comment


            • #7
              Code:
              bysort Inventorid (patentyear): gen wanted = firmid != firmid[_n-1] & _n > 1
              bysort Inventorid firmid (patentyear): replace wanted = 0 if _n > 1

              Comment


              • #8
                Originally posted by Wouter Wakker View Post
                Code:
                bysort Inventorid (patentyear): gen wanted = firmid != firmid[_n-1] & _n > 1
                bysort Inventorid firmid (patentyear): replace wanted = 0 if _n > 1
                many thanks Wouter!

                Comment

                Working...
                X