Announcement

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

  • Replace observations with missing values (dot)

    I have a dataset where I have two variables ("ff_jbstat" and "ethn_dv") in a likert scale. Some on the answer are not labeled, namely: in "ff_jbstat" there is an answer named "11" and in the variable "ethn_dv" tehre is an answer named "56". Can you help me with the code to replace those observations with a missing value (dot)?
    I send an exmaple of the dataset below.
    Thank you in advance



    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(hgpart ff_jbstat ethn_dv)
    . 3  1
    2 4  1
    1 3  1
    2 2  1
    1 2  1
    . 2  1
    2 4 11
    1 2  1
    . .  1
    2 2  1
    . 2  1
    . 4  1
    . 8  1
    . 3  4
    2 2  1
    1 6  7
    2 2  1
    1 .  1
    . 1  4
    2 6 10
    1 2 10
    . . 14
    . 2  1
    2 3  1
    1 2  5
    . 2  1
    . 4  4
    2 2  1
    1 2 12
    . 2  1
    2 2  4
    . 1 97
    . 1  1
    2 4  1
    1 4  1
    . 2 14
    . 7 10
    7 1 10
    2 2  9
    1 2  9
    . 2  9
    . 7  9
    . 7  9
    2 1 10
    1 6 10
    1 6 10
    2 . 10
    . 4 14
    . 1  7
    . 3  8
    . .  5
    2 1 10
    1 2  1
    2 2 13
    1 2  1
    . 2 13
    . 2 13
    2 2  5
    1 2  1
    2 6  9
    . 1 97
    . 7 11
    2 2 12
    1 2  4
    . 7 11
    . . 11
    . 7 12
    . 1  5
    . 2 15
    2 2 14
    . 2 14
    1 6 10
    . 2 10
    . 7 10
    . . 10
    . 1 14
    . 4  8
    1 1 15
    . 2 12
    . 2 13
    2 1  9
    1 2  9
    . 7  9
    . 4 97
    2 2 15
    1 2 15
    . 7 15
    . 3  6
    2 3 10
    . 7 10
    . 7 10
    1 2 13
    2 2 11
    1 1 11
    . 2 15
    . 2 14
    . 2  1
    . 2  8
    2 3  9
    2 2 16
    end
    label values hgpart c_hgpart
    label values ff_jbstat c_ff_jbstat
    label def c_ff_jbstat 1 "self employed", modify
    label def c_ff_jbstat 2 "in paid employment (full or part-time)", modify
    label def c_ff_jbstat 3 "unemployed", modify
    label def c_ff_jbstat 4 "retired", modify
    label def c_ff_jbstat 6 "looking after family or home", modify
    label def c_ff_jbstat 7 "full-time student", modify
    label def c_ff_jbstat 8 "long-term sick or disabled", modify
    label values ethn_dv c_ethn_dv
    label def c_ethn_dv 1 "british/english/scottish/welsh/northern irish", modify
    label def c_ethn_dv 4 "any other white background", modify
    label def c_ethn_dv 5 "white and black caribbean", modify
    label def c_ethn_dv 6 "white and black african", modify
    label def c_ethn_dv 7 "white and asian", modify
    label def c_ethn_dv 8 "any other mixed background", modify
    label def c_ethn_dv 9 "indian", modify
    label def c_ethn_dv 10 "pakistani", modify
    label def c_ethn_dv 11 "bangladeshi", modify
    label def c_ethn_dv 12 "chinese", modify
    label def c_ethn_dv 13 "any other asian background", modify
    label def c_ethn_dv 14 "caribbean", modify
    label def c_ethn_dv 15 "african", modify
    label def c_ethn_dv 16 "any other black background", modify
    label def c_ethn_dv 97 "any other ethnic group", modify

  • #2
    Try this:
    Code:
    local vars ff_jbstat ethn_dv
    
    foreach var of varlist `vars' {
        decode `var', gen(_`var')
        replace `var' = . if !missing(`var') & missing(_`var')
        drop _`var'
    }
    Last edited by Hemanshu Kumar; 09 Sep 2022, 14:31.

    Comment


    • #3
      It worked! Thank you very much

      Comment

      Working...
      X