Exodia16
Exodia16

Reputation: 177

How do I convert string variables to numeric variables in Stata?

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.

Upvotes: 6

Views: 48210

Answers (2)

user19552830
user19552830

Reputation: 1

destring varname, replace ignore(xyz)      

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

Upvotes: 0

Metrics
Metrics

Reputation: 15458

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

Or,

encode var, generate(var1)

Upvotes: 7

Related Questions