Announcement

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

  • How to remove the invisible space between "-" symbol in Stata.

    Hello, I have a small dataset below,
    clear
    input str80 No str90 Project
    "F-BGBU03" "BG2020 - Fannin to US 59"
    "F-BGBU04" "BG2020 - Memorial Park Connection"
    "F-BGBU04" "BG2020 - Memorial Park Connection"
    end
    I want to remove the invisible space before and after "-" symbol in Stata.
    Thank you for your help!

  • #2
    assuming that this is only for the variable named Project and that the first part is always 6 characters long, try
    Code:
    replace Project = substr(Project,1,6)+substr(Project,8,1)+substr(Project,10,.)

    Comment


    • #3
      Rich, under the conditions you described, why not just use subinstr(Project," - ","-",1)?

      Code:
      replace Project = subinstr(Project," - ","-",1)
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        Thank you!

        Comment


        • #5
          Bruce Weaver - because I didn't happen to think of it while reading the question <grin>

          Comment

          Working...
          X