6

I have two variables in Stata, both numeric variables that have somehow been recorded as string variables. I need them converted to numeric variables so that I can generate a new variable with them.

When I tried, it said type mismatch I have tried the real and the encode commands, none of which are working.

1
  • It always help to show exactly what code you tried. Note that real() is a function in Stata, not a command. Commented Jul 26, 2013 at 18:48

2 Answers 2

7

Try destring var, replace in Stata if you want to convert var into numeric

Or,

encode var, generate(var1)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, i realised it was string because there were some 'NA' in the dataset, i deleted them and it was fine. !
0
destring varname, replace ignore(xyz)      

xyz is any non-numeric character in the value of the variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.