Announcement

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

  • Concatenating strings piece by piece

    Dear Statalisters,

    I want to concatenate two string variables. Instead of combining them using e.g. concat() I need them to be combined "piece-wise". That is, letter 1 in variable A (e.g. gender) corresponds to letter 1 in variable B (e.g.origin) and so on. Ideally, a delimiter should be added between the "pieces".

    What I have:
    Code:
    clear  
    input str20 (A B)   
    1111 2345
    end
    What I need:
    Code:
    clear  
    input str20 (A B C)   
    1111 2345 12_13_14_15
    end
    There might be solutions available that combine multiple loops and temp variables, but I was wondering if there is a more straightforward way to do this. Naturally, the actual number of observations is much larger and I am aware that this is not an optimal way to organize data.

    Thank you and best regards
    Sebastian

  • #2
    Originally posted by Sebastian Schirner View Post

    I want to concatenate two string variables. Instead of combining them using e.g. concat() I need them to be combined "piece-wise".
    This is an interesting problem, but you have posted it on the wrong forum. Repost it on the General Forum.

    Comment


    • #3
      Thank you for making me aware of this mistake. The post is in the other forum now.

      Comment


      • #4
        Reposted and answered at https://www.statalist.org/forums/for...piece-by-piece

        Comment

        Working...
        X