Announcement

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

  • Dropping multiple cities in one command

    Dear Stata users,
    I am using a panel data consisting of 352 municipalities for 2000-2020 and would like to drop a city if it has a missing value for the independent variable house price. So that would mean multiple cities in one command to be removed.
    What I have done so far is to see which cities have missing values for houseprice variable by using
    Code:
    br GM_code log_realHP if log_realHP==.
    This way i know which cities have missing values now that I know which cities they are I have to drop these cities in one command .

    I have tried this command:
    Code:
    drop GM_code if GM_code==14    22    28    31    36    37    44    53    64    66    68    76    86    90    92    102    106    109    113    137    143    144    145    148    153    158    160    166    167    171    173    175    182    187    190    192    195    196    199    205    206    216    219    221    228    231    233    235    246    254    260    262    264    267    273    275    276    280    282    285    293    304    312    321    323    326    327    332    347    350
    no luck so far

  • #2
    Adam:
    what about:
    Code:
    drop if log_realHP==.
    That said, I would warmly recommend you to save a copy of your original dataset before -drop- (just in case...).
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Originally posted by Carlo Lazzaro View Post
      Adam:
      what about:
      Code:
      drop if log_realHP==.
      That said, I would warmly recommend you to save a copy of your original dataset before -drop- (just in case...).
      Hi sir thanks again for helping me out, I have tried this the problem is it doesnt delete the municipality as a whole, what is left is that municipalities with values remain in the dataset and only those missing years are deleted.

      Comment


      • #4
        Adam:
        you may want to try something along he following lines, that is elaborated on one of your yesterday's post:
        Code:
        . sort GM_naam real_consCost
        
        . bysort GM_naam: drop if real_consCost[_N]==.
        Change the variables when needed.
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          I have a better idea (I think, perhaps someone will out-fox me here).

          Why not just do

          Code:
          qui levelsof mun if log_real== ., l(miss_mun)
          
          foreach xm of loc miss_mun {
          
          drop if mun==`xm'
          }
          This IDs the unique IDs of municipalities that have ANY missing values for the variable, and then drops them like a hot pan.

          Comment


          • #6
            Originally posted by Jared Greathouse View Post
            I have a better idea (I think, perhaps someone will out-fox me here).

            Why not just do

            Code:
            qui levelsof mun if log_real== ., l(miss_mun)
            
            foreach xm of loc miss_mun {
            
            drop if mun==`xm'
            }
            This IDs the unique IDs of municipalities that have ANY missing values for the variable, and then drops them like a hot pan.
            Thanks a lot I will try this code

            Comment

            Working...
            X