Announcement

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

  • Drop all observations of a city if var missing or zero

    Hi everyone,

    I have this data of incomes of cities in Brazil from 2000-2016. I want to drop all observations of this city if the var 'recprop' = 0 or missing:

    Click image for larger version

Name:	Screenshot_23.jpg
Views:	1
Size:	183.1 KB
ID:	1673870



    How can I do this in Stata?

  • #2
    Code:
    bys cidade: egen todrop= max(missing(recprop)| !recprop)
    drop if todrop
    see FAQ https://www.stata.com/support/faqs/d...ble-recording/

    Comment


    • #3
      The brilliant code that Andrew shows depends on

      Code:
      . dis !0
      1
      However

      Code:
      . dis !0.00000000000000000000000000000000001
      0
      I do not know whether the second can happen for recprop in this data, but if it happens the code will not filter out the 0s.

      It might be safer to write this as

      Code:
       
       egen minprop= min(cond(missing(recprop),0,recprop)), by(cidade)  drop if minprop< 0.5

      Comment

      Working...
      X