Announcement

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

  • Replacing missing values

    Dear All,

    I have the following (maybe silly) problem, which I cannot solve.

    I have the following data:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 iso_o str52 country_o str3 iso_d str52 country_d byte col float(csl cnl prox1 lp1 prox2 lp2 cl cle) str32 NAMES_STD
    "BLX" "Belgium and Luxembourg" "AFG" "Afghanistan"         0    .000273     .000273   .25 1.9458665 .10716087  .9601701 .12580793 .12667672 "Belgium"
    "BLX" "Belgium and Luxembourg" "ALB" "Albania"             0          0           0   .25 1.9458665  .1070556  .9592268 .12544584 .12631404 "Belgium"
    "BLX" "Belgium and Luxembourg" "DZA" "Algeria"             1   .4988294     .005642     0         0  .0707655  .6340647 .21813615   .212725 "Belgium"
    "BLX" "Belgium and Luxembourg" "AND" "Andorra"             1   .6889079    .1747249 .2328  1.811991 .10901195  .9767559   .388072 .38383695 "Belgium"
    "BLX" "Belgium and Luxembourg" "AGO" "Angola"              0     .00648      .00486 .3575  2.782589 .18500473 1.6576574  .2205917 .22208473 "Belgium"
    "BLX" "Belgium and Luxembourg" "AIA" "Anguilla"            0  .54362804     .000828 .3925   3.05501 .26269874 2.3538022  .3083989  .3105275 "Belgium"
    "BLX" "Belgium and Luxembourg" "ATG" "Antigua and Barbuda" 0     .47272     .000702 .3925   3.05501 .26269874 2.3538022  .3083116  .3104406 "Belgium"
    "BLX" "Belgium and Luxembourg" "ARG" "Argentina"           0 .070164636  .009493327 .3575  2.782589 .17853823  1.599717  .2167152 .21814933 "Belgium"
    "BLX" "Belgium and Luxembourg" "ARM" "Armenia"             0    .000455     .000455   .25 1.9458665 .07627013  .6833866 .08978632 .09040457 "Belgium"
    "BLX" "Belgium and Luxembourg" "ABW" "Aruba"               1   .3139827  .036364388  .465  3.619311 .17659363 1.5822933  .3617912  .3573743 "Belgium"
    "BLX" "Belgium and Luxembourg" "AUS" "Australia"           0  .57412785 .0011027019 .3925   3.05501 .26269874 2.3538022   .308589  .3107171 "Belgium"
    "BLX" "Belgium and Luxembourg" "AUT" "Austria"             1   .6199744     .003456  .535 4.1641545  .3099715   2.77737   .495746  .4922561 "Belgium"
    "BLX" "Belgium and Luxembourg" "AZE" "Azerbaijan"          0    .008918     .006916     0         0 .08643995   .774509  .1075043 .10820045 "Belgium"
    "BLX" "Belgium and Luxembourg" "BHS" "Bahamas"             0    .514083     .000711 .3925   3.05501 .26269874 2.3538022  .3083179  .3104468 "Belgium"
    "BLX" "Belgium and Luxembourg" "BHR" "Bahrain"             0    .007917     .005005     0         0  .0707655  .6340647 .08751174 .08808276 "Belgium"
    "BLX" "Belgium and Luxembourg" "BGD" "Bangladesh"          0    .011818           0   .25 1.9458665 .12923352 1.1579429 .15143356  .1524816 "Belgium"
    "BLX" "Belgium and Luxembourg" "BRB" "Barbados"            0  .58502465 .0009269314 .3925   3.05501 .26269874 2.3538022  .3084673  .3105958 "Belgium"
    "BLX" "Belgium and Luxembourg" "BLR" "Belarus"             0    .000364     .000364   .25 1.9458665  .1200436 1.0756004 .14097776 .14195092 "Belgium"
    "BLX" "Belgium and Luxembourg" "BLZ" "Belize"              0    .497039 .0038411426 .3799  2.956939 .23240095 2.0823314  .2751184  .2769959 "Belgium"
    "BLX" "Belgium and Luxembourg" "BEN" "Benin"               1     .22594           0     0         0         0         0 .13077809 .12476233 "Belgium"
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    "LUX" "Luxemburg"              ""    ""                    .          .           .     .         .         .         .         .         . ""      
    end

    I would like to replace the missing values for Luxembourg with the same data that I have for Belgium & Luxemburg. I tried to do it one by one using for instance:

    Code:
    replace iso_d=iso_d in 21/40 if NAMES_STD=="Belgium"
    However nothing happens. My question is how I can do this and whether there is a way to replace all the variables in one shot.

    Thanks in advace
    Last edited by Dario Maimone Ansaldo Patti; 02 Sep 2019, 04:15.

  • #2
    In your data example there are no observations satisfying the two qualifiers simultaneously.

    Code:
     
     in 21/40 if NAMES_STD=="Belgium"
    so nothing happens. in and if are combined using logical and, not logical or.


    Comment


    • #3
      Nick Cox Thanks Nick. Do you mean something like:

      Code:
      if NAMES_STD=="Belgium" & in 21/40

      Comment


      • #4
        No; I don't mean that. That is illegal and if it were legal it would do the same thing/ I am just explaining that in and if work together that way. Here's another example:

        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . list make in 1/20 if foreign
        Note the list shows no observations. There are no foreign cars in the first 20 observations.

        As for your problem, it seems that you have no separate data for Luxembourg but just joint data for Belgium and Luxembourg. So, I would just drop those problematic observations.

        Comment


        • #5
          Nick Cox. Ok. I see now. Thanks for your explanation

          Comment

          Working...
          X