**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!
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!

Comment