Announcement

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

  • replacing multiple variables to "0" for a logistic regression?

    Hello all,

    I am very new to the stata world and I am having some trouble with a question that was separated in a questionnaire about the source. It is actually 10 questions but in a,b,c,d,e.. format, e.g. Qn32a, Qn32b, Qn32c...Qn32k. I have the following command when it comes to my new variable for source:

    generate source = .
    replace source = 0 if Qn32b == 1
    replace source = 0 if Qn32c == 1
    replace source = 0 if Qn32d == 1
    replace source = 0 if Qn32e == 1
    replace source = 1 if Qn32f == 1
    replace source = 0 if Qn32g == 1
    replace source = 0 if Qn32h == 1
    replace source = 0 if Qn32i == 1
    replace source = 0 if Qn32j == 1
    replace source = 0 if Qn32k == 1

    Qn32a is the never selection and makes no real changes. Would this be the correct way to group my sources if I am only interested in Qn32f?

  • #2
    You need to be way more clear on what you are trying to accomplish if you want help.

    Comment


    • #3
      Welcome to Statalist.

      Let me give a very narrow answer to your question.

      Your code would fail if an individual were able to choose more than one source, and that's often the reason why what seem to be "multiple choice" questions are coded as multiple variables.

      Suppose an individual chose f and j. Then you would first set source to 0, then to 1 for f, then back to 0 for k.

      A more reliable approach might be
      Code:
      generate source = .
      replace source = 0 if inlist(1, Qn32a, Qn32b, Qn32c, Qn32d, Qn32e, Qn32g, Qn32h, Qn32i, Qn32j, Qn32k)
      replace source = 1 if Qn32f==1
      But I not comfortable recommending this without a better understanding of your data. Please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to use the dataex command to provide sample data, as described in section 12 of the FAQ.

      Comment

      Working...
      X