Announcement

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

  • converting string to numerical

    I just uploaded someone's Excel datafile, and there are a bunch of categorical variables which are numbered in Excel but show up in Stata as string. When I "destring" the variables this is the error message I get:
    Age: contains nonnumeric characters; no replace
    Race: contains nonnumeric characters; no replace
    Ethnicity: contains nonnumeric characters; no replace
    RaceEthnicityCoding: contains nonnumeric characters; no replace
    PatientStatus: contains nonnumeric characters; no replace
    Barrier: contains nonnumeric characters; no replace

    Is it because the Excel cells include blank spaces? If so, how do I fix this? All ideas appreciated thank you!

  • #2
    We can't see any of your data to tell you what the non-numeric characters are. See e.g. #5 of https://www.statalist.org/forums/for...iable-problems for a command you can use, but the main idea is simpler:

    Code:
    foreach v in Age Race Ethnicity RaceEthnicityCoding PatientStatus Barrier {
         di "`v'"
         di
         tab `v' if missing(strofreal(`v'))
    }
    That is, you need Stata to show you, and you can then show us, which values of each variable could not converted simply to numeric values.

    The answer is likely to be to use destring with particular options.

    Comment


    • #3
      Thank you. Solved

      Comment


      • #4
        Excellent, but a hint at what the problem was and how you solved it might be of use or interest to people finding this thread in future.

        Comment


        • #5
          I am using someone else's dataset and rushing and she had instructed me to import the whole sheet without mentioning that way at the bottom out of obvious view she had done calculations/etc in Excel which screwed up data! Sorry for the false alarm.

          Comment


          • #6
            Or I can just use Pearson's (which runs without error) because while 2 cells have only 5 observations, only 1 of the expected has <5 and that is way < 20%?

            Comment


            • #7
              #6 is posted in the wrong thread.

              Comment


              • #8
                Anyhow thanks for your help I really appreciate it

                Comment

                Working...
                X