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
Structural Equation Modelling (SEM) using STATAHi, I want to analyze my data using SEM in stata. This is my model: Array Health variable consist of…
Help with rounding off in STATAI am new to Stata and I need to create a three-way table. I was trying to export it using "asdoc tab…
robust standard errors using Mata-based d0 ml evaluator using _robust developers' functionDear Statalist, I have a model fitted using ml using a d0 Mata-based evaluator. Now, I am trying to…
Can you make ridgeline plots (aka joyplots) in Stata 16?Hi! I stumbled on this data visualization page https://www.data-to-viz.com/ and realized that ridge…
Merge while keeping value labels in master and using dataset unchangedHello! I am trying to merge two datasets from a survey which contains household ((HH) level data wi…
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