Announcement

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

  • About Multiple response variable

    Hi family,
    I have multiples choice question that I splited them into 4 variable base on the command I came across, with a yes for option that were chosen and for the choice that were not chosen it indicates as missing response since that was not selected.

    example,
    saq4: Select the source of the information(Multiple response)
    A. School(Selected)
    B. Home.
    C. Television(selected)
    D. Other

    So in column saq4= AB as text

    After conversion,
    using the command below that i came across;

    foreach j in A B C D{
    gen saq4`j'=regexm(saq4,"`j'")
    recode saq4`j' (0=.)
    la val saq4`j' yn
    }

    lab var saq4A "Does not visit home regularly"
    lab var saq4B "Does not answer calls"
    lab var saq4C "Does not attend social events"
    lab var saq4D "No development"

    I got four(4) additional newly created variable with response as seen below;

    saq4A saq4B saq4C saq4D
    yes . yes .

    example of the structure after conversion, the rest,

    OS. saq4A saq4B saq4C saq4D
    1 . Yes . yes
    2. yes . . .

    .
    .
    .

    20. . yes yes yes

    I used the command
    mrtab saq4A saq4B saq4C saq4D

    Though I got some statistics but I was not too sure.

    Because the examples that I came across, they used 0 for no and 1 as yes but in my case I have missing(.) as no and yes for the responses.
    Can you please confirmed for me

    I attached example data set for your perusal.
    . dataex

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int zabea_id str4 saq4 str6 saq5
     1 "D"   "ABCDE" 
     2 "D"   "ABCDE" 
     3 "D"   "ABCDE" 
     4 "BD"  "BDE"   
     5 "BCD" "ABCDE" 
     6 "CD"  "BDE"   
     7 "D"   "BDEF"  
     8 "D"   "C"     
     9 "D"   "ADEF"  
    10 "D"   "DE"    
    11 "D"   "DE"    
    12 "A"   "DF"    
    13 "D"   "DE"    
    14 "D"   "DF"    
    15 "D"   "DF"    
    16 "D"   "ABCDE" 
    17 "D"   "ABCDE" 
    18 "D"   "ABCDE" 
    19 "A"   "ABCDEF"
    20 "D"   "ABCDE" 
    15 "D"   "ABCDE" 
    end

    I would be glad if there is also another easy way to handle it I will appreciate that.

    Thank you.

    Sham.

  • #2
    I am not quite sure what the question is here, as your data example contradicts much of what you say earlier. However,

    Code:
    foreach v in A B C D E F {
         gen saq5_`v'  = strpos(saq5, "`v'") > 0
    }


    gets you a bundle of (0, 1) indicator variables.

    See https://journals.sagepub.com/doi/pdf...867X1101100308 for a round-up of functions that -- in the author's opinion -- every long-term user of Stata would benefit from knowing.
    Last edited by Nick Cox; 17 Apr 2023, 01:22.

    Comment


    • #3
      Hi Nick,
      Thank you very much Sir.

      Sorry I for got to add this command

      la def yn 1 "Yes"

      before the focast loop.

      I used only one variable saq4 to run the command.
      However, I think I am okay. what you have provide makes it much easier. I will also make good use of the link you share to improve my understanding.

      I am so grateful.

      Comment

      Working...
      X