Announcement

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

  • How to find nonnumeric characters within a string variable and lists the observations that have this issue

    I want to identify which observations in my variable has non-numeric characteristics and what is these non-numeric characteristic before I use destring and its options.
    The destring command will only work if the string variable we are trying to convert to numeric contains no non-numeric characters. For example, if we have a variable coded as “0” or “1”, but in a given observation, it was coded by mistake as “1b”, the destring command will not work. When dealing with small databases, it might be easy to visually identify which observation was wrongly coded. However, this process might be difficult if we have a large database containing many observations.

    Is there any Stata command that searches for non-numeric characters within a string variable and lists the observations that have this issue?

  • #2
    why not try the following:
    Code:
    ta var if real(var)==.
    where you need to replace "var" with your variable name (note that there are 2 places in the command where "var" occurs)

    if you really need to know which observations have issues, use the -list- command instead of, or in addition to, the -tabulate- command
    Last edited by Rich Goldstein; 03 Mar 2023, 05:07.

    Comment


    • #3
      Thank you very much, Rich Goldstein!!

      Comment


      • #4
        See also https://www.statalist.org/forums/for...iable-problems for a problemstring command.

        Comment


        • #5
          Thank you very much, Nick cox!!

          Comment

          Working...
          X