Thursday, April 18, 2019

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 !

No comments:

Post a Comment