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
Related Posts with Non-numeric string variable with missing value to numeric variable that recognises the missing value
using "spmap"Hi guys, I am trying to map the result by using "spmap" command, yet keep having troubles with the …
Writing loop for multiple regressionsI have 10 dependant variables, y1-y30, and its respective lagged variables, lagy1-lagy30. I would li…
How to present vignettes in a tabular formatHello everyone, Could you please help me to present vignettes in a tabular format rather than a run…
The base year for finding yearly effects of the shock in DIDI wanted to estimate a difference-in-differences model using Stata looking at the effects of a trade…
GEE and distributional assumptionsHello all, I am using GEE to estimate my dependent variable. The dependent variable has a lower bou…
Subscribe to:
Post Comments (Atom)
0 Response to Non-numeric string variable with missing value to numeric variable that recognises the missing value
Post a Comment