Announcement

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

  • Expanding the list of observations

    Hello,

    I've been wrapping my head around the following problem but could not come up to a feasible and simple solution.

    Essentially, I need to go from this structure
    Code:
    Firm1    Firm2    StartYear    EndYear
    1    2    2010    2012
    1    3    2010    2013
    4    5    2008    2009
    5    6    2007    2007
    to this one
    Code:
    Firm1    Firm2    Year
    1    2    2010
    1    2    2011
    1    2    2012
    1    3    2010
    1    3    2011
    1    3    2012
    1    3    2013
    4    5    2008
    4    5    2009
    5    6    2007
    So essentially, I need to create data for each Firm1-Firm2 combination ranging from the start year to the end year.

    Would be thankful for any help.

  • #2
    Code:
    clear 
    input Firm1    Firm2    StartYear    EndYear
    1    2    2010    2012
    1    3    2010    2013
    4    5    2008    2009
    5    6    2007    2007
    end 
    
    gen toexpand = End - Start + 1 
    expand toexpand 
    bysort Firm1 Firm2 : gen Year = StartYear[1] + _n - 1 
    list, sepby(Firm1 Firm2)

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      clear
      input Firm1 Firm2 StartYear EndYear
      1 2 2010 2012
      1 3 2010 2013
      4 5 2008 2009
      5 6 2007 2007
      end
      
      gen toexpand = End - Start + 1
      expand toexpand
      bysort Firm1 Firm2 : gen Year = StartYear[1] + _n - 1
      list, sepby(Firm1 Firm2)
      Thank you very much, Nick!

      Comment

      Working...
      X