Announcement

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

  • Help with problem in creating variable that describes one event occurring at least once

    Hello. I'm new to this forum, and quite new to Stata in general, as I just started using it for the work in my thesis.

    I have come across a problem that I can't seem to solve. In my data, i have, among a lot more data, a collection of firms and data about if they innovated or not. Something like this:


    Year ID innovation
    2007 1 0
    2008 1 23
    2009 1 0
    2007 2 45
    2008 2 48
    2007 3 0
    2008 3 0
    2009 3 0
    2007 4 34
    2007 5 0

    What I need to do is to create a variable, innovator, that would be 0 if a firm never innovated, and 1 if it innovated at least one time during the time it is in the database. In this case, innovator would be 1 for company 1, 2 and 4 and it woukd be 0 for company 3 and 5.
    How can I solve this? I've tried to do

    generate innovator = 0
    replace innovator = 1 if innovation >0

    but this will give values of innovator==1 only for the year in which the firm innovated, and that's not what I need.

    Any help would be much appreciated !

  • #2
    there are different ways to do this; one "easy" way to just continue with what you have done is:
    Code:
    egen byte innovator2=max(innovator), by(ID)
    you could then drop your innovator variable if you want

    Comment


    • #3
      A direct way to proceed is

      Code:
      bysort ID (innovation) : gen wanted = innovation[_N] > 0
      although this needs modification if missing values are present. That's why the egen route recommended by Rich is justifiably often considered better.

      Comment

      Working...
      X