Announcement

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

  • Replace a observation by a missing value

    I would like to know the command to replace the observations where it is written "refusal" and "don´t know" in the variable "resunsafe1_11" by a missing value (.).
    I send an example of the dataset below.
    Thank you very much in advance.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(pidp hidp) byte(pno resunsafe1_11 resunsafe2_11 resunsafe3_11)
      68513407   71114404 1  0  0  0
      69394015   75595604 3  0  0  0
      69406247   75629604 1  0  0  0
      69451131   75711204 2  0  0  0
      69854367   76098804 1  0  0  0
     136376727  138264404 1  0  0  0
     136591607  139468004 1  0  0  0
     136591615  139468004 3  0  0  0
     137389927  143949204 1  0  0  0
     137436167  143996804 1  0  0  0
     137779567  144350404 1  0  0  0
     204068691  204462404 2  0  0  1
     204595687  207454404 1  0  0  1
     204595691  207454404 2  0  0  1
     205007775  209712004 1  0  0  0
     205420535  211724804 2  1  0  0
     205604807  211949204 1  0  0  0
     205786367  212119204 1  0  0  0
     205958407  212398004 1  0  0  0
     206224967  212554404 1  0  0  0
     272165931  272979204 2  0  0  0
     340061887  340360404 1  0  0  0
     340434527  342550004 1  0  0  0
     341325331  347330404 2  0  0  0
     341419847  347514004 1  0  0  0
     341537487  347629604 1  0  0  0
     341691167  347888004 1  0  0  0
     341764607  347949204 1  0  0  1
     342008727  348214404 1  0  1  0
     342014847  348228004 1  1  1  0
     342222247  348357204 1  0  0  0
     342222251  348357204 2  0  0  0
     342222259  348357204 4  0  0  0
     408041487  408292404 1  0  0  0
     408205367  409251204 1  0  0  0
     409638807  415854004 1  0  0  0
     409653091  415874404 2  0  0  0
     409693207  415922004 1  0  0  1
     409733327  415996804 1  0  0  0
     409779571  416030804 2  0  0  0
     409847567  416132804 1  0  0  0
     409897211  416200804 2  0  0  0
     410126371  416493204 2  0  0  0
     410131127  416500004 1  0  0  0
     410230407  416568004 1  0  0  0
     476000691  476006804 2  0  0  0
     478404487  484275604 1  0  0  1
     545284531  551337204 2  0  0  0
     545532047  551854004 1  0  0  0
     545532055  551854004 2  0  0  0
     545781607  551996804 1  0  0  0
     546314047  552595204 1  0  0  0
     546524847  552690404 1  0  0  1
     546761499  552942004 2  0  0  0
     546766931  552962404 2  0  0  0
     612193131  613292004 2  0  0  0
     612621527  616059604 1 -1 -1 -1
     612677971  616433604 2  0  0  0
     613438887  620194004 1  0  0  0
     613518455  620234804 3  0  0  0
     613783651  620479604 1  1  1  0
     613806087  620520404 1  0  0  0
     614375931  620982804 2  0  0  0
     680330491  681917604 2  0  0  0
     680954047  685202004 1  0  0  0
     680962211  685276804 2  0  0  0
     681007099  685542004 1  0  0  0
     681551087  687554804 1  0  0  0
     681585767  687561604 1  0  0  0
     681717687  687772404 1  0  0  0
     681717691  687772404 2  0  0  1
     681792487  687847204 1  1  0  0
     748594327  751481604 1  0  0  0
     749419847  755656804 1  0  0  1
     750244007  756336804 1  0  0  0
     750505807  756534004 1  0  0  0
     817670087  824071604 1  0  0  0
     817992411  824642804 2  0  0  0
     884224415  885197484 1  0  0  0
     884536527  886896804 1  0  0  0
     884616767  887325204 1  0  0  0
     885250527  890582404 1  0  0  0
     885392651  891051604 2  0  0  0
     885861167  891650004 1  0  0  0
     886011447  891826804 1  0  0  0
     886012127  891833604 1  0  0  0
     886305207  892166804 1  0  0  0
     886346691  892200804 2  0  0  0
     886428967  892289204 1  0  0  0
     886558847  892384404 1  0  0  0
     952242767  953455204 1  0  0  0
     953100931  958018004 2  0  0  0
     953649019  959643204 4  0  0  0
     953905367  959962804 1  0  0  1
     954174651  960377604 2  0  0  0
     954463647  960608804 1  1  0  1
    1022476567 1028574804 1  0  0  0
    1089592567 1095439204 1  0  0  0
    1089592571 1095439204 2  0  0  0
    1089644247 1095507204 1  1  1  0
    end
    label values resunsafe1_11 c_resunsafe1_11
    label def c_resunsafe1_11 -1 "don't know", modify
    label def c_resunsafe1_11 0 "not mentioned", modify
    label def c_resunsafe1_11 1 "mentioned", modify
    label values resunsafe2_11 c_resunsafe2_11
    label def c_resunsafe2_11 -1 "don't know", modify
    label def c_resunsafe2_11 0 "not mentioned", modify
    label def c_resunsafe2_11 1 "mentioned", modify
    label values resunsafe3_11 c_resunsafe3_11
    label def c_resunsafe3_11 -1 "don't know", modify
    label def c_resunsafe3_11 0 "not mentioned", modify
    label def c_resunsafe3_11 1 "mentioned", modify

  • #2
    Code:
    replace resunsafe1_11 = . if resunsafe1_11 == -1

    Comment


    • #3
      Thank you very much. The command worked perfectly

      Comment

      Working...
      X