Announcement

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

  • Variable indicating whether an outcome has happened

    Hi list,

    I'm stuggling to create some indicator variables and wondering if anyone can help me on this.

    I have a event based data set showing outcomes of an event occuring in countries and years. I want to create a variable indicating whether a particular outcome has previously occured in a country. In addition, I would like to create another variable showing the amount of years since the outcome last occured in each country.

    I'm grateful for all advises.

    Best regards,
    Magne

  • #2
    If you have an indicator that is 1 in an event year and 0 otherwise, then the number of events to date is just the cumulative sum of that indicator within panels; and an indicator for "has previously happened" can be calculated from that cumulative sum (or its previous value).

    The time since the last event is just (current date - date of last event), so you must carry forward the date of the last event..

    Code:
    webuse grunfeld, clear 
    gen event = invest > 400 
    gen last = year if event 
    bysort company (year) : replace last = last[_n-1] if missing(last) 
    by company : gen happened = sum(event) 
    gen time_since = year - last 
    edit

    Comment


    • #3
      Perfect. Thank you very much for the quick reply.

      Comment


      • #4
        I'll just add that if you read the Statalist Advice, http://www.statalist.org/forums/help#gfaq_postingadvice, you will see the request to use full real names. Please do so in future posts.
        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment

        Working...
        X