Announcement

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

  • Create byte variables from a concatenate string variable

    I have a string variable which is from concatenation of responses to 11 questions (A,B,C,D,...,K). Please, how I can proceed to "deconcatenate" this string (str11) variable to 11 binary (byte) variables ? Thanks.

  • #2
    Already answered at https://www.statalist.org/forums/for...g-and-a-number

    Comment


    • #3
      Thank you.

      Comment


      • #4
        Sorry to come back. The string (variable Q21) consists of alphabetical characters, that is "A,B,C,D,E,F,G,K". Based on what your suggestion,I tried instead the following without success
        forval j = A/K {
        gen byte Q21`j'= real(substr(Q21, `j', 1))
        }

        Comment


        • #5
          edit Q21
          Q21
          ABC EFG I
          A CD GH
          ABC EFG
          A C E G
          A C G
          A C G
          ABCD H
          A CD G
          A CD G
          ABCDE GH
          A CD GH
          A C GH
          ABCD GH
          ABCD G
          ABCD GH
          A C
          A
          ABC GH
          ABC H
          ABCDEF H

          Here is the data example.

          I was able to try this syntax. But it requires for all string value.
          gen Q21A = 0
          replace Q21A = 1 if strpos(Q21,"A") >= 1
          edit Q21A Q21 if Q21A == 0 *** Checking
          Last edited by Armand Mboutchouang; 08 May 2024, 05:38.

          Comment

          Working...
          X