Generating new variable but issue with float?

Generating new variable but issue with float?

by Kimberly Kallianos -
Number of replies: 3

Hi all, 

For my final project I am trying to clean my data and change a current variable "phtn" which has responses as Yes and No into a new variable ("confirmed" with 1 and 0).  However I keep getting a type mismatch error when I attempt to make this change, and was wondering if it might be because my Yes/No variable is somehow coded as float rather than string.  Could this be the problem?  If so, what should I do to fix it?  I have included the syntax below which I have tried many times without success.

gen confirmed=0
replace confirmed = 1 if phtn == "Yes"

Thanks!  

Kim

In reply to Kimberly Kallianos

Re: Generating new variable but issue with float?

by Bliss Temple -

Just to be sure I understand, are you saying that you can see that your yes/no variable is coded as a float when you look at the variable properties, or that you think this is what may have happened?

In reply to Bliss Temple

Re: Generating new variable but issue with float?

by Kimberly Kallianos -

Yes, I used the describe command to confirm that it is coded as float.

 

 

In reply to Kimberly Kallianos

Re: Generating new variable but issue with float?

by Mark Pletcher -

Right, so the "Yes" and "No" are simply labels as opposed to actual variable values.

Try

codebook phtn

so you can see what the actual values are associated with Yes and No.  Then you can redo your code as:

gen confirmed=0
replace confirmed = 1 if phtn == 1

(assuming 1 = "Yes", etc.)