Announcement

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

  • To transform cross-section data to panel data

    Dear Sir/Madam,

    I am doing the research on commercial jet aircraft, and each sample has "lease start date" and "lease end date". Using these data, I would like to transform the dataset into panel data. Is there any command which can be used for?
    ID Type Lease End Lease Start
    A 737-800 2022/12/31 2017/1/1
    B 777-300ER    
    C A320    
     ↓
    ID Type Lease End Lease Start Year Lease
    A 737-800 2022/12/31 2017/1/1 2017 1
            2018 1
            2019 1
            2020 1
            2021 1
            2022 1
            2023 0
    Best regards,
    Mayuko Kimura

  • #2
    So the first thing is to import the data into Stata and create proper Stata internal format date variables for Lease End and Lease Start. Once you have done that:

    Code:
    gen start_year = year(lease_start)
    gen end_year = year(lease_end)
    
    expand end_year - start_year + 2
    by id, sort: gen year = start_year + _n - 1
    by id (year), sort: gen lease = (_n < _N)
    
    drop *_year
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Dear Clyde,

      Thank you very much for your kind help. I could transform the data successfully.
      Noted to use -dataex- for my future posts.

      Many thanks,
      Mayuko

      Comment

      Working...
      X