

It converts string values to numeric values. If you are sure that observations with non-numeric characters are not needed, you can use the real() function with generate command. Instead, it gives you an error message when there are non-numeric characters in the variable. The destring command is useful in a sense that it does not convert data to missing observations.

#Converting excel to stata in stat transfer code
The following code creates a new variable numvar destring strvar, ignor("#error" "#na" "*") gen( numvar) We can specify these in the ignore option. The above tables shows that there are three non-numeric variables in our dataset. tabulate strvar if missing(real( strvar)) Opening/saving a Stata datafile Quick way of finding variables Subsetting (using conditional if) Stata color coding system From SPSS/SAS to Stata Example of a dataset in Excel From Excel to Stata (copy-and-paste. Suppose that the above code comes up with a list of the following non-numeric characters. Suppose that our variable strvar contains non-numeric values tabulate strvar if missing(real( strvar )) We can list all non-numeric characters using the tabulate command and the real() function. *Now destring the two variables destring price, replace ignore(",") 1.2 List all non-numeric characters See the following example: *First create a dummy data In such cases, we can use the ignore(“,”) option, which tells Stata that the given character i.e. If there are non-numeric characters in our dataset, destring command will show an error non-numeric characters foundįor example, our data might have comma separators, therefore, destring will generate the above error. *Now destring the two variables destring price, replace destring return, replace 1. Here is an example: *First create a dummy data input str15(price return) With this command, we can either generate a new variable or replace the existing one. The destring command might be the first choice for converting string variables to numeric if we have a limited number of non-numeric characters. Let’s start with the destring command first. If a numeric variable is stored as a string variable in Stata, we have several ways to convert them to numeric variables.
#Converting excel to stata in stat transfer how to
In this post, I show how to convert string variables to numeric in Stata. Paid Help – Frequently Asked Questions (FAQs).
