Announcement

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

  • type mismatch error on numeric variable

    **Editing to add: I resolved the problem! I don't know why but when I generated the problembinary variable it apparently was a string variable. Once I destringed that variable the commands worked. If anyone knows why it automatically was a string variable I am curious to know if I did something wrong there!


    Hello, I am getting a type mismatch error on a numeric variable and can't figure out what I am doing wrong.

    gen problembinary=.
    replace problembinary=1 if c01_999==0
    replace problembinary=0 if c01_999==1
    replace problembinary=. if c01_999==.

    The error comes after the first replace command. c01_999 is a numeric variable. If I describe it I get the following:
    describe c01_999

    storage display value
    variable name type format label variable label
    ----------------------------------------------------------------------------------------------
    c01_999 byte %8.0g 999 I have not experienced any problems


    If I tab it I get the following:
    tabulate c01_999

    999 I have |
    not |
    experienced |
    any |
    problems | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 1,355 33.49 33.49
    1 | 2,691 66.51 100.00
    ------------+-----------------------------------
    Total | 4,046 100.00


    So I think the command should work, the only thing I can think of is something with the spacing? Anyone have any insights? I have Stata/SE 16.1 for Windows. Thanks!
    Last edited by Rachel Taylor; 29 Jan 2025, 03:10.

  • #2
    Can you show us the exact commands and error message from Stata? Better still, copy and paste the output from

    Code:
    dataex in 1/20

    Comment


    • #3
      It's hard to say or see what went wrong here. For future reference

      Code:
      gen problembinary = 1 - c01_999
      flips 0 and 1 and maps missings to missings.

      Comment

      Working...
      X