I have a string variable in the form as below:
delivery
air
ship
ship
air
air
NA
NA
ship
air
air
I am trying to convert the above strings with non-numeric values such that air is assigned a label value of 0 and ship is assigned a label value of 1, while also recognising NA as missing value.
So far I have tried destring/generate, resulting in the following error:
[destring delivery, ignore ("NA") gen (delivery_new)]
[delivery: contains characters not specified in ignore(); no generate]
Similarly, I tried encode, which converted strings to numeric successfully, but still does not recognise the missing values:
[label define deliverylabel 0 "ship" 1 "air"
encode delivery, gen (delivery_new) label (deliverylabel)]
I am not sure what is the best way to tackle this. Any insights will be hugely appreciated.
Thanks,
Keshab
0 Response to Non-numeric string variable with missing value to numeric variable that recognises the missing value
Post a Comment