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
Calculating the expected return of Eurostoxx 50 with STATA (Event Study)Hello everyone, currently I am working on an event study with the Eurostoxx 50 Index as underlying m…
How can I get return list of estat endogenous after a 2sls?Hello,everyone.I want to define results of extat endogenous to be a local.But I find that I can't ge…
Can I run a Pseudo-Poisson Maximum Likelihood in panel data when not using a Gravity Model? What is the STATA command?I want to run the Pseudo-Poisson Maximum Likelihood (PPML) in a panel data framework as my dependent…
color/line pattern for graph?Dear All, I found the following code Code: sysuse auto, clear regress price c.length##c.mpg est s…
Excluding leading zeros when exporting output to WORDHi folks, can you recommend a command that could help me export regression output without including …
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