Announcement

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

  • Drop entire panel/id when at least one value missing

    Hi

    I`m currently working on trimming a panel dataset, but my technical skills in STATA are somewhat limited. Anyone able to help?

    The dataset consists of company id, year and industry codes (code) for six years. For some companies the industry code is either entirely missing or partially missing. I want to remove a company from the dataset entirely if there are no industry codes or if industry codes are not given for the entire time period in which a company is in the dataset.

    In the example I have given, I would want to drop all observations for id 203, not only the one where the code is missing.

    Thank you very much.


  • #2
    From e.g. http://stackoverflow.com/questions/3...ndition-is-met it follows that


    Code:
    bysort id (code) : drop if missing(code[1]) | missing(code[_N])
    will drop panels if any value of code is missing in that panel, regardless of whether the variable is string or numeric.

    Please note:

    http://www.statalist.org/forums/help#stata don't post photo attachments, post data as CODE

    http://www.statalist.org/forums/help#spelling Stata, not STATA

    Comment


    • #3
      Thank you for your time.

      Best
      Thomas

      Comment


      • #4
        My panel set is comparable with the example given above, although mine is ranging from 2011 - 2019. I want to drop the whole ID if at least 1 value misses for the ID excluding the year 2011. Can anyone help me with the code?

        Kind regards,

        Philip

        Comment

        Working...
        X