Announcement

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

  • Issue with destring ignore nonnumeric

    Hello,
    I am cleaning a large dataset and for most of my variables, I have successfully transformed string to numeric, replacing non-numeric characters. However, for a handful of variables, the non-numeric 'ignore' command ends up dropping the non-numeric categorized data. So for example, my string variable ER_visits has labels 0, 1, 2, and UK. And I wish to destring and ignore 'UK', replacing it with a numeric '3'.
    the code I am using is

    destring ER_visits, generate(ER_use) ignore(' "UK" ')

    when I tabulate the new variable I only see values for 0, 1, 2. All of the values for 'UK' appear to have been dropped.

    Any idea why this might be? Many thanks in advance!


  • #2
    destring expects number strings only.

    Code:
    replace  ER_visits="3" if trim(ER_visits)=="UK"
    destring ER_visits, generate(ER_use)

    Comment


    • #3
      UK could mean United Kingdom, unknown, and much else besides.

      If you specify that UK is to be ignored nothing will be dropped (in Stata's sense of drop) it just won't show up in tables unless you ask for it. UK alone will get mapped to missings..

      Comment


      • #4
        Hello,

        Thank you both for taking the time to reply, it's much appreciated.

        Andrew, your code was exactly what I was looking for. Many thanks!
        This was my first time using the statalist forum and I'm incredibly grateful for the assistance.

        Comment

        Working...
        X