Announcement

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

  • Issues with recoding command

    Hi I have two variables comment_lawyer (numeric variable) and comment_other (string variable).

    comment_lawyer has 2 values: 0 (no lawyer) and 1 (yes lawyer). comment_other has values such as "therapist", "lawyer", "major lawyer", "doctor" etc.

    There were errors in data entering so that some "lawyer" responses were entered into comment_other instead of comment_lawyer. I am trying to recode the comment_lawyer variable so that any value that accessed a lawyer, based on the comment_lawyer and comment_other, are recoded correctly. I am only trying to recode where the word "lawyer" is explicitly stated in values in the comment_other variable (i.e. "lawyer" would be included, "major lawyer" would be included etc. etc.)

    I am having difficulty using the recode command for this (assuming this is the right code), any help would be greatly appreciated!

  • #2
    Please give example data and code using dataex. See the FAQ for more.

    Comment


    • #3
      You wouldn't use recode for this task. Try something along the following lines instead.
      Code:
      replace comment_lawyer = 1 if strpos(strlower(comment_other), "lawyer")

      Comment


      • #4
        Originally posted by Joseph Coveney View Post
        You wouldn't use recode for this task. Try something along the following lines instead.
        Code:
        replace comment_lawyer = 1 if strpos(strlower(comment_other), "lawyer")
        Thank you for this Joseph! This worked! Except there are a couple of values in the comment_other variable such as "unqualified lawyer" which under the code you helpfully wrote out are unfortunately being included (given the value includes the word "lawyer"), but I do not wish to be included. Any suggestions how to code for this?

        Comment


        • #5
          Code:
          replace comment_lawyer = 1 if strpos(strlower(comment_other), "lawyer") & !strpos(strlower(comment_other),"unqualified lawyer")

          Comment


          • #6
            Originally posted by Hemanshu Kumar View Post
            Code:
            replace comment_lawyer = 1 if strpos(strlower(comment_other), "lawyer") & !strpos(strlower(comment_other),"unqualified lawyer")
            Worked perfectly - thank you very much

            Comment

            Working...
            X