Announcement

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

  • Panel data - dropping cross section based on missing values

    In a panel dataset, there are companies with revenues for multiple years.

    I would like to drop all companies if their revenue information is missing for any year.

    Is there a simple way to achieve this?

    In SQL, I would do something like:
    Code:
    DELETE FROM table WHERE company_id IN (SELECT DISTINCT company_id WHERE sales(t)=0 AND sales(t-1)>0)
    Last edited by Pratap Pundir; 31 Jan 2019, 05:02.
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    Pratap:
    dropping (missing) observations in not a good habit, as missingness can be informative.
    That said, you may want to consider something along the following lines:
    Code:
    set obs 10
    g panelid=1 in 1/5
    replace panelid=2 if panelid==.
    g revenue=1000*runiform() in 1/8
    bysort panelid: gen flag=1 if revenue==.
    replace flag=0 if flag==.
    bysort panelid: egen total=total( flag )
    drop if total>0
    drop flag
    drop total
    list
    
         +--------------------+
         | panelid    revenue |
         |--------------------|
      1. |       1   348.8717 |
      2. |       1   266.8857 |
      3. |       1   136.6463 |
      4. |       1   28.55687 |
      5. |       1   868.9333 |
         +--------------------
    
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks Carlos!

      Could I simply go:
      Code:
      gen flag = 0
      replace flag = 1 if revenue == .
      bysort company_id: egen total=total(flag)
      drop if total > 0
      drop flag total




      Thank you for your help!

      Stata SE/17.0, Windows 10 Enterprise

      Comment


      • #4
        Yes.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X