Announcement

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

  • How to generate variables from the information within a multiple choice question variable

    Dear All,
    I have a dataset where one of the variables represents a multiple-choice question, but all responses are recorded within a single variable. What I need to do is create several dummy variables corresponding to each option in the multiple-choice question. Each dummy variable should be assigned a value of 1 if the response includes the respective option, and 0 if it does not.



    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str270 N
    "lack of education qualification"                                                                             
    "lack of education qualification"                                                                             
    "lack of personal confidence, i have a good job/ business at hand, cannot spare time from my household chores"
    "lack of education qualification"                                                                             
    "lack of personal confidence, lack of education qualification"                                                
    "lack of education qualification"                                                                             
    "lack of personal confidence"                                                                                 
    "never got opportunities from any party"                                                                      
    "lack of personal confidence"                                                                                 
    "never got opportunities from any party"                                                                      
    "lack of personal confidence"                                                                                 
    "never got opportunities from any party"                                                                      
    "never got opportunities from any party"                                                                      
    "i have a good job/ business at hand"                                                                         
    "i have a good job/ business at hand"                                                                         
    "i have a good job/ business at hand"                                                                         
    "discouraging socio-cultural environment for women to participate, i have a good job/ business at hand"       
    "never got opportunities from any party, gender biases society"                                               
    "never got opportunities from any party, i have a good job/ business at hand"                                 
    "lack of personal confidence"                                                                                 
    "i have a good job/ business at hand"                                                                         
    "i have a good job/ business at hand"                                                                         
    ""                                                                                                            
    ""                                                                                                            
    end
    ------------------ copy up to and including the previous line ------------------

    Could copy only few data since there is a limit. For example : lack of personal confidence, i have a good job/ business at hand, cannot spare time from my household chores" : convert it into thre

    These are the options in my multiple choice question:
    lack of personal confidence
    Discouraging socio-cultural environment for women to participate
    Never got opportunities from any party
    I have a good job/ business at hand
    Cannot spare time from my household chores
    Gender biases society
    Lack of education qualification

    So I want in total 7 dummy variables to be created
    For Example: lack of personal confidence, i have a good job/ business at hand, cannot spare time from my household chores" : this particular data point will have "1" in all three of these options and 0 in the other.

    Thank you in advance.

  • #2
    Code:
    local response1    lack of personal confidence
    local response2    discouraging socio-cultural environment for women to participate
    local response3    never got opportunities from any party
    local response4    i have a good job/ business at hand
    local response5    cannot spare time from my household chores
    local response6    gender biases society
    local response7    lack of education qualification
    
    forvalues i = 1/7 {
        gen byte response`i' = strpos(N, `"`response`i''"') > 0
    }
    Note: This code relies on exact string matching. That means that the text contained in variable N must match the response exactly in terms of spelling, capitalization, internal spacing, and internal punctuation. So your data set must be thoroughly cleaned before you use this.

    Comment

    Working...
    X