Announcement

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

  • Dropping whole panel if one or more values are missing in a certain time period

    Hello,

    I have a panel data set with thousands of firms, firm ID, date for end of accounting year (time variabel), total assets and cash. The data set is in long format.
    I want to exclude (not drop from the data set) the whole firm if one or more values of either total assets or cash (or both) is missing in the time period of 2005-2010. I have yearly data.
    I have tried to generate a variabel which is = 1 if: bysort ID: gen OK = 1 if total_assets != . & cash != . & years_data > 9. The latter variabel is generated as: bysort ID: gen years_data = [_N].

    However, when i look at the column i have created, I see that it includes several firms and don't drop the whole firm as i wish.

    So, the main question is: how can I exclude the entire firm from further calculations if one or more values of total assets and/or cash is missing between year 2005-2010?

    Thank you in advance

  • #2
    Code:
    bysort ID: gen OK = 1 if total_assets != . & cash != . & years_data > 9
    here has the same effect as

    Code:
    gen OK = 1 if total_assets != . & cash != . & years_data > 9
    I would turn this round as

    Code:
    bysort ID : egen n_bad = total(cond(inrange(year, 2005, 2010), missing(total_assets, cash), 0)) 
    
    gen is_good = n_bad == 0

    Comment


    • #3
      Thank you so much!

      Comment

      Working...
      X