Announcement

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

  • Panel Data: Add another year/row for each group

    Hi!

    I have a panel dataset for a set of companies and like to extend the time period for two more years although I have no data yet in my sample (will merge that later)
    Is there a possibility to ad two years as rows for each of the companies in the sample?

    E.g. right now I have Company X with the ds_code 5566 for 2010 to 2015 and I like to extend it until 2017.

    Thanks a lot for you help!

  • #2
    Since this is a thing I've always wondered how to do (but never had to because I make my panels and times first), I think this question would benefit you, us, and others if you showed you example data using dataex.

    A minimal worked example with a toy dataset helps us, help you, as well as anyone else who'd need to do this in the future. So please, use dataex to provide a subsample of your data.

    Comment


    • #3
      Hi Jared;

      of course hopefully the outut helps to describe what I am looking for:
      I like to add a row (2018) for each company identified by its unique ds_code

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str6 ds_code float year str99 companyname
      "130062" 2010 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2011 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2012 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2013 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2014 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2015 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2016 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130062" 2017 "MARTIN MARIETTA MATERIALS INC"                                                     
      "130298" 2004 "ALBEMARLE CORPORATION"                                                             
      "130298" 2005 "ALBEMARLE CORPORATION"                                                             
      "130298" 2006 "ALBEMARLE CORPORATION"                                                             
      "130298" 2007 "ALBEMARLE CORPORATION"                                                             
      "130298" 2008 "ALBEMARLE CORPORATION"                                                             
      "130298" 2009 "ALBEMARLE CORPORATION"                                                             
      "130298" 2010 "ALBEMARLE CORPORATION"                                                             
      "130298" 2011 "ALBEMARLE CORPORATION"                                                             
      "130298" 2012 "ALBEMARLE CORPORATION"                                                             
      "130298" 2013 "ALBEMARLE CORPORATION"                                                             
      "130298" 2014 "ALBEMARLE CORPORATION"                                                             
      "130298" 2015 "ALBEMARLE CORPORATION"                                                             
      "130298" 2016 "ALBEMARLE CORPORATION"                                                             
      "130298" 2017 "ALBEMARLE CORPORATION"                                                             
      "130375" 2010 "QLOGIC CORP"                                                                       
      "130375" 2011 "QLOGIC CORP"                                                                       
      "130375" 2012 "QLOGIC CORP"                                                                       
      "130375" 2013 "QLOGIC CORP"                                                                       
      "130375" 2014 "QLOGIC CORP"                                                                       
      "130375" 2015 "QLOGIC CORP"                                                                       
      "130375" 2016 "QLOGIC CORP"                                                                       
      "130375" 2017 "QLOGIC CORP"                                                                                                                              
      "13951F" 2010 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2011 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2012 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2013 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2014 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2015 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2016 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13951F" 2017 "ALLIANCE DATA SYSTEMS CORP"                                                        
      "13967C" 2004 "FMC TECHNOLOGIES INC"                                                              
      "13967C" 2005 "FMC TECHNOLOGIES INC"                                                              
      "13967C" 2006 "FMC TECHNOLOGIES INC"                                                              
      "13967C" 2007 "FMC TECHNOLOGIES INC"                                                              
      end

      Comment


      • #4
        to add two years,
        Code:
        bys ds_code (year): gen x = _n==_N
        expand 3 if x
        bys ds_code (year): replace year = year + sum(x) if sum(x)>1

        Comment

        Working...
        X