Announcement

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

  • How to recode a string variable

    Hi there I am trying to group ages into three groups (15-24) (25-34) (35-49) and generate a new variable using the function

    recode age_woman (15/24= 1 "15/24") (25/34= 2 "25/34") (35/49= 3 "35/49"), generate (agegroups) label (agegroups)

    However when i do that I get the following error: recode only allows numeric variables r(108);

    Any idea where I am going wrong? I did the same thing for mens age and it worked fine.

    Cheers,
    Jess


  • #2
    As age_woman appears to be a string variable recode can't be used unless you destring first.

    But there is probably extra stuff in the variable that caused it to be read in as numeric.

    Code:
     
    tab age_woman if missing(real(age_woman))
    You had better check what else has been misread as string.

    Comment


    • #3
      Thanks Nick, one of the values has appeared as --- , so I am assuming I need to code that as a missing value?

      Comment


      • #4
        I guess you need to specify ignore(-) in a destring call.

        Comment


        • #5
          Let me nitpick Nick's semantics. I wouldn't say that age_woman has been misread as string. Rather, whoever created the source data that Jessica started with miscoded at least one value of that variable using characters inadmissible for numeric variables.

          But that said, Nick's larger point is right: a data source that contains one error like this is very likely to contain others. Particularly if the source of the data is a spreadsheet, people often take those liberties with the data. Every variable that is supposed to be numeric needs to be checked. I'd probably start with -ds, has(type string)- and scrutinize the output for names of variables that should contain only numbers.

          Comment


          • #6
            Thanks Clyde and Nick this information has been very useful.

            Comment


            • #7
              Clyde is right.

              You had better check what else has been misread as string.

              should have been something more like

              You had better check what else has been misread as string given your intentions.

              Comment

              Working...
              X