Announcement

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

  • How to drop sequence of observations when the observations are zero sequently

    I am now cleaning my firm-level data. I have panel data which contains 19,150 observations/year for 2010-2015. I have done the following command in STATA 14.0 to indicate my panel data:

    xtset firmcode, year yearly

    Then I would like to drop the observation if its capital is zero during six year (2010-2015). Here is the example of my data:

    Year firmcode capital

    2010 24 0
    2011 24 0
    2012 24 0
    2013 24 0
    2014 24 0
    2015 24 0
    2010 25 0
    2011 25 0
    2012 25 1000
    2013 25 0
    2014 25 0
    2015 25 0

    As the firm with firmcode 24 does not have data of its capital so I will remove it, so my data will remain only firm with firmcode 25, as follows:

    Year firmcode capital

    2010 25 0
    2011 25 0
    2012 25 1000
    2013 25 0
    2014 25 0
    2015 25 0

    Would you please help how to write the command for this?

    Best regards,
    Aisah
    Last edited by Aisah Aisah; 07 Mar 2019, 03:50.

  • #2
    Hi Aisah,

    One way to do it would be to generate 2010-15 capital total and drop if it is 0. I am assuming that data timespan is strictly 2010-15 and capital cannot be negative. In that case,

    Code:
    by firmcode, sort: egen k_total = total(capital)
    drop if k_total == 0

    Comment


    • #3
      Hi Ashish Tyagi,

      Thank you very much for your help. The command worked well.
      Last edited by Aisah Aisah; 07 Mar 2019, 05:29.

      Comment


      • #4
        If the smallest and largest values for each panel are both 0, then all values are 0.

        Code:
        bysort Year (capital) : drop if capital[1] == 0 & capital[_N] == 0

        Comment


        • #5
          Thank you very much. It is very helpful.

          Comment

          Working...
          X