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.
destring; tostringdestring/tostring, replace or destring/tostring, generate() converts string variables to numeric variables and vice versa.
The storage type of variables can be changed with the help of the recast command. Here, numeric variables can be changed to a different numeric type, and string variables to a different string type (i.e. different string length). will ask Stata to change the storage type of variable income to "long".
To recode variables in Stata, use the recode command. To use recode , you must provide a list of variables to be recoded and the rules associated with that change.
One common reason for this problem is that the data have been imported from a spreadsheet or something similar. Some users of Excel or similar programs get in the habit of putting several lines of header material before the body of their data.
Try destring var, replace
in Stata if you want to convert var
into numeric
Or,
encode var, generate(var1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With