Announcement

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

  • Removing observations that do not contribute data in a time series

    Hello Statalisters,

    I am working with a timeseries dataset similar in structure to that one available on
    Code:
    webuse grunfeld, clear
    My dataset has a lot of missingness and I would like to clean my dataset by removing observations that do not contain values for specific variables throughout the entirety of the time series. For example, in the dataset above, suppose there was a lot of missingness in variables kstock and mvalue but there were companies that did not have any data for through the time series. How can I drop just the latter companies? Any suggestions would be greatly appreciated.

  • #2
    Your description of what you want is, to me, unclear. In the context of the grunfeld data set, which of these is the condition for which you would want to drop the company:

    A. All values of both kstock and mvalue are missing.
    B. All values of kstock are missing or all values of mvalue are missing.
    C. There are no observations with non-missing values for both kstock and mvalue.

    All of those strike me as plausible interpretations of "did not have any data through the time series." They require different code, and, of course, will give different results.

    Please clarify.

    Comment


    • #3
      Hi Clyde, thanks for the response. I am not sure I understand the nuance between conditions A and C, but I know I would certainly like to drop companies meeting condition A.

      Comment


      • #4
        Code:
        gen byte both_missing = missing(kstock) & missing(mvalue)
        by company (both_missing), sort: drop if both_missing[1]
        The difference between A and C in # 2 is this:

        If some observations have kstock, and only kstsock, missing, and all of the other observations have mvalue, and only mvalue, missing, this would satisfy condition C, but not condition A.

        Comment


        • #5
          This makes sense. Thank you for the clarification and for the code!! Much appreciated

          Comment

          Working...
          X