Announcement

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

  • Remove panel IDs under a specific condition

    Hello,

    I am having trouble removing PANELIDs that do not fulfill a specific condition. I want to delete all the PANELIDs in which they have at least one observation (quarter) where the ret variable is greater than or equal to 0.

    Code:
    input float(time PANELID ret)
    156 1           .
    157 1           .
    158 1           .
    159 1           .
    160 1           .
    161 1           .
    162 1           .
    163 1           .
    164 1           .
    165 1           .
    166 1           .
    167 1           .
    168 1           .
    169 1           .
    170 1           .
    171 1           .
    172 1           .
    173 1           .
    174 1           .
    175 1           .
    176 1           .
    177 1           .
    178 1           .
    179 1           .
    180 1           .
    181 1           .
    182 1           .
    183 1           .
    184 1           .
    185 1           .
    186 1           .
    187 1           .
    188 1           .
    189 1           .
    190 1           .
    191 1           .
    192 1           .
    193 1           .
    194 1           .
    195 1           .
    196 1           .
    197 1           .
    198 1           .
    199 1           .
    200 1           .
    201 1           .
    202 1           .
    203 1           .
    204 1           .
    205 1           .
    206 1           .
    207 1           .
    208 1           .
    209 1           .
    210 1           .
    211 1           .
    212 1           .
    213 1           .
    214 1           .
    215 1           .
    216 1           .
    217 1           .
    218 1           .
    219 1           .
    220 1           .
    221 1           .
    222 1           .
    223 1           .
    224 1           .
    225 1           .
    226 1           .
    227 1           .
    228 1           .
    229 1           .
    230 1           .
    231 1           .
    232 1           .
    233 1           .
    234 1           .
    235 1           .
    236 1           .
    237 1           .
    238 1           .
    239 1 -.003631074
    240 1 -.002085845
    241 1 -.006522712
    242 1  .002849518
    243 1   -.0024905
    244 1   .00367562
    245 1  .000116491
    246 1  -.00245067
    247 1  .000749183
    248 1 -.000203197
    249 1 -.000801834
    250 1  .000653891
    251 1 -.000147365
    252 1  .001484411
    253 1 -.002455185
    254 1 -.000204286
    156 2           .
    end
    format %tq time
    label values PANELID PANELID
    label def PANELID 1 "Austria 1", modify
    label def PANELID 2 "Austria 2", modify

    My first thought was to remove observations that are greater or equal to 0 and are not missing values.

    Code:
    bys PANELID: drop if ret>= 0 & ret!=.
    So I end up with an unbalanced dataset with missing date observations.

    Code:
    input float(time PANELID ret)
    156 1           .
    157 1           .
    158 1           .
    159 1           .
    160 1           .
    161 1           .
    162 1           .
    163 1           .
    164 1           .
    165 1           .
    166 1           .
    167 1           .
    168 1           .
    169 1           .
    170 1           .
    171 1           .
    172 1           .
    173 1           .
    174 1           .
    175 1           .
    176 1           .
    177 1           .
    178 1           .
    179 1           .
    180 1           .
    181 1           .
    182 1           .
    183 1           .
    184 1           .
    185 1           .
    186 1           .
    187 1           .
    188 1           .
    189 1           .
    190 1           .
    191 1           .
    192 1           .
    193 1           .
    194 1           .
    195 1           .
    196 1           .
    197 1           .
    198 1           .
    199 1           .
    200 1           .
    201 1           .
    202 1           .
    203 1           .
    204 1           .
    205 1           .
    206 1           .
    207 1           .
    208 1           .
    209 1           .
    210 1           .
    211 1           .
    212 1           .
    213 1           .
    214 1           .
    215 1           .
    216 1           .
    217 1           .
    218 1           .
    219 1           .
    220 1           .
    221 1           .
    222 1           .
    223 1           .
    224 1           .
    225 1           .
    226 1           .
    227 1           .
    228 1           .
    229 1           .
    230 1           .
    231 1           .
    232 1           .
    233 1           .
    234 1           .
    235 1           .
    236 1           .
    237 1           .
    238 1           .
    239 1 -.003631074
    240 1 -.002085845
    241 1 -.006522712
    243 1   -.0024905
    246 1  -.00245067
    248 1 -.000203197
    249 1 -.000801834
    251 1 -.000147365
    253 1 -.002455185
    254 1 -.000204286
    156 2           .
    157 2           .
    158 2           .
    159 2           .
    160 2           .
    161 2           .
    162 2           .
    end
    format %tq time
    label values PANELID PANELID
    label def PANELID 1 "Austria 1", modify
    label def PANELID 2 "Austria 2", modify
    The question is: Can I delete all the PANELIDs with missing date observations at this point or is there a more efficient and easier way to do it in the first place?

    Thank you in advance!

    Christos

  • #2
    Note that

    Code:
     
     bys PANELID: drop if ret>= 0 & ret!=.
    has the same effect as
    Code:
      
     drop if ret>= 0 & ret!=.
    I don't follow your question. No dates are missing, but some are absent. Isn't that an unsurprising consequence?

    If you want to drop entire panels you need something different, namely something like

    Code:
    bys PANELID : egen bad_count = total(ret >= 0 & ret < .) 
    drop if bad_count
    although I don't follow why the missing values are any use.

    Comment


    • #3
      Thank you for the quick response!

      Comment

      Working...
      X