Announcement

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

  • Remove specific characters from all value labels

    I'm trying to remove specific phrases each time they occur in every value label of my dataset. For example, I want to remove the text "[DON'T READ]" in the label "[DON'T READ] Don't know".
    This problem is similar to this resolved Statlist question, except I am trying to change value labels and not variable labels.

    I tried this, but I get an r(198) "invalid syntax" error. Perhaps am going about this in entirely the wrong way. Is it even possible to do this?

    Code:
    foreach i of varlist _all {
    local a : value label `i'
    local a: subinstr local a "[DON'T READ] " ""
    label define `i' "`a'"
    }

  • #2
    See labutil2 (SSC) and therein labvalch3

    Code:
    labvalch3 * , strfcn(subinstr("@", "[DON'T READ]", "", .))
    Edit: If you wanted to program this yourself, you would need to loop through all integer to text mappings inside the value labels.

    Best
    Daniel
    Last edited by daniel klein; 12 Oct 2017, 09:20.

    Comment


    • #3
      Really nice solution, Daniel. Thanks!

      Comment

      Working...
      X