Announcement

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

  • Question about recoding a variable, having issues with deleting some unwanted values.

    Hello everybody.

    I am a stata beginner, trying to do some descriptive analysis on a survey data.
    My version of stata is stata/IC 15.0.

    There is a variable with 8 values in the survey. - 1, - 2, 1, 2, 3, 4, 5 and 6, that I would like to have an one way table for this variable.
    The problem is here: - 1, - 2 and 6 are not valid values, so they shouldn't be take into account while calculating the table. And at the same time I can't drop people with these values, because they have valid observations for other varibles in the survey.
    I tried to recode the variable in order to make a new one only with valid values and get rid of - 1, - 2 and 6.

    recode perm3d - 2 - 1 6=. 1=1 2=2 3=3 4=4 5=5 , gen (perm)
    but I get this error: unknown el - in rule
    r(198);

    Can you help with this issue pleas?
    Thanks.

  • #2
    Stata parses on spaces, so when you type recode perm3d - 2 - 1 6=. , Stata thinks you want to change five elements to missing: -, 2, -, 1, and 6. However, recode expects numerical values, not '- ', hence "unknown el - ". Removing the spaces for the negative values should solve the problem.
    Last edited by Wouter Wakker; 21 Jul 2019, 02:27.

    Comment


    • #3
      I'm pretty sure that -recode- requires parentheses around the rules - see
      Code:
      help recode
      also, however, if your "invalid" values are to be treated as missing, you will find the -mvdecode- command easier; see
      Code:
      help mvdecode

      Comment


      • #4
        Thank you gentlemen! I checked both solutions and got the (same) answer.
        Much appreciated!

        Comment

        Working...
        X