Announcement

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

  • Help Command to generate a new variable

    Hello, here is a part of the data of the firms with different id.
    I'd like to generate a new variable that equals the current year if the firm first time has positiv revenue.
    For example, firm id =2 first time has a positive revenue in 2012, the the NewVar=2012 for firm id= 2.
    I manually generate the NewVar to help you to understand what I want.
    Thanks for the help!

    -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte id int(revenue year NewVar)
    1 100 2010 2010
    1  98 2011 2010
    1 103 2012 2010
    1 110 2013 2010
    1 106 2014 2010
    1 107 2015 2010
    2   0 2011 2012
    2  95 2012 2012
    2   0 2013 2012
    2  99 2014 2012
    2  98 2015 2012
    3  80 2013 2013
    3  90 2014 2013
    3 100 2015 2013
    4   0 2010 2011
    4  79 2011 2011
    4  89 2012 2011
    4  97 2013 2011
    5   0 2010    .
    5   0 1011    .
    5   0 2012    .
    5   0 2013    .
    end
    ------------------

  • #2
    Try this:
    Code:
    bysort id: egen int wanted = min(cond(revenue>0,year,.))
    assert wanted == NewVar

    Comment

    Working...
    X