Announcement

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

  • reversal of encode

    numeric codes

  • #2
    Hi all, I'm a newbie. I am working on a data set with over 500,000 string codes for one variable and decided to encode them (Using stata15) to numeric codes to keep their value labels That worked but now, when I want to keep a subset of the variable by value labels, I don't know how to do this. I tried

    Keep if var = value label this got a = not allowed
    keep if var = "value label"
    keep if var =="value label" this got a mismatch error

    So then I tried looking at destring but that's a different function
    I tried using labmatch if var = "value label" thinking I might get the numeric value matched with the value labels I want but this came back with "something missing".

    Not sure how to approach this as the data set is so large

    Comment


    • #3
      Actually my terminology is wrong - I did say I'm new - I was doing "keep if var = value" variations (not value label)

      Comment


      • #4
        Ok, so when you used encode, either you specified a value label name, or it specified one automatically. Let's call it "lbl_var"

        If you want to keep only observations with the value label "value_label" in your variable "var", you should use:

        Code:
        keep var if var == "value_label":lbl_var

        Comment


        • #5
          Excellent. Thanks so much!

          Comment

          Working...
          X