Announcement

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

  • Delete firms from panel data having no observation

    Dear Statlists

    I am working on R&D investment of Panel data of more than 2900 firms and study period is 2005-2015. Problem is that most of the firms have not R&D observations. I want to keep only those firms which have at least on year observation of R&D, and all the remaining one I want to delete form sample. For example, company 2 has no observation for R&D, so it must be deleted. how can I do that?

    input int(year id) RDinv
    2004 2 .
    2005 2 .
    2006 2 .
    2007 2 .
    2008 2 .
    2009 2 .
    2010 2 .
    2011 2 .
    2012 2 .
    2013 2 .
    2014 2 .
    2015 2 .
    2004 3 .
    2005 3 .
    2006 3 .
    2007 3 .
    2008 3 .
    2009 3 .
    2010 3 5767031.08
    2011 3 2952345.13
    2012 3 2460888.19
    2013 3 1936084.84
    2014 3 2439346.8
    2015 3 4265023.32

  • #2
    Kaleem:
    you can try:
    Code:
    drop if RDinv==.
    However, although tecnically feasible, please note that Stata would do it by defaut, by applying listwise deletion to all the observations with at least one missing value in any variable.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo

      Thank you so much for guidance. I applied it but it deletes all missing R&D observations. I want to delete only those firms which don't have any R&D observations.

      Like for this dataex

      input int(year id) RDinv
      2004 2 .
      2005 2 .
      2006 2 .
      2007 2 .
      2008 2 .
      2009 2 .
      2010 2 .
      2011 2 .
      2012 2 .
      2013 2 .
      2014 2 .
      2015 2 .
      2004 3 .
      2005 3 .
      2006 3 .
      2007 3 .
      2008 3 .
      2009 3 .
      2010 3 5767031.08
      2011 3 2952345.13
      2012 3 2460888.19
      2013 3 1936084.84
      2014 3 2439346.8
      2015 3 4265023.32


      The solution must be like this:

      input int(year id) RDinv
      2004 3 .
      2005 3 .
      2006 3 .
      2007 3 .
      2008 3 .
      2009 3 .
      2010 3 5767031.08
      2011 3 2952345.13
      2012 3 2460888.19
      2013 3 1936084.84
      2014 3 2439346.8
      2015 3 4265023.32

      is it possible?

      Comment


      • #4
        Kaleem:
        surely there are more elegant solutions but the one that springs to my mind at present is the following one:
        Code:
        bysort id: egen flag=total( RDinv)
        drop if flag==0
        Last edited by Carlo Lazzaro; 01 May 2017, 05:21.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Code:
          bysort id (RDinv) : drop if missing(RDinv[1]) & missing(RDinv[_N])

          Comment


          • #6
            Thank you so much Carlo and Nick. It worked.

            Comment

            Working...
            X