Announcement

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

  • Recoding Existing Variables

    Hi,
    I have a large data set and I am trying to recode one of my indicator variables which currently uses "Y" and I want to change all the "Y"s to equal 1
    The variable currently looks like this:

    Code:
    residential
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    Y
    I have tried using the recode command
    Code:
    recode residential ("Y" = 1)
    but I receive this error:

    Code:
    unknown el Y in rule
    r(198);
    
    end of do-file
    Is there a way to do this?

  • #2
    If you'd like the new variable to be actually a numerical variable, then it'd be easier to to generate a new one:

    Code:
    gen residential2 = .
    replace residential2 = 1 if residential == "Y"
    You can also use the same replace command to convert the rest to 0, etc.

    Comment


    • #3
      Thank you Ken! That worked.

      Comment


      • #4
        See also the help for encode

        Comment

        Working...
        X