Announcement

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

  • Deleting leading spaces in some labels

    Hello everyone,
    in my dataset, I have some variables that have a leading space in the labels of variables.
    If I use this code:
    foreach v of varlist * {
    local lbl: var label `v'
    local lbl: subinstr local lbl " " "", all
    label var `v' `"`lbl'"'
    }
    all the spaces are removed but I want to keep them and delete the leading space (if present). How can I do it?

  • #2
    Use ltrim() on the label or

    Code:
    foreach v of varlist * {
    local lbl: var label `v'
        if substr(`"`lbl'"', 1, 1) == " " {
            local lbl = substr(`"lbl'", 2, .)
            label var `v' `"`lbl'"'
        }
    }

    Comment


    • #3
      Thank you so much Nick Cox! The code works perfectly.
      Have a good day

      Comment

      Working...
      X