Announcement

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

  • Combine two strings with entry that has more information

    Dear statalists,

    I have two variables that capture the same thing but with differing precision. One can imagine the data like this
    Name1 Name2
    Joe David Alex Joe David
    Stephen Henry Stephen Henry Jr.
    I am trying to think of a procedure to create a third variable that will contain the entry of either of the two variables where more information is stored. The criteria would then be that the string is longer, but I still cannot translate that into code right now. Does anybody have ideas?

    Thank you!

  • #2
    Code:
    gen longer = cond(length(Name1) >= length(Name2), Name1, Name2)
    trim(itrim()) would do no harm to avoid spurious comparisons based on extra spaces.

    Comment


    • #3
      On point, thanks Nick!

      Comment

      Working...
      X