The destring is one of the main commands used to clean databases in Stata, as it can be used to convert string variables to numeric variables. This is a very important feature, especially if a database from another source (e.g. Excel) is imported into Stata.
The destring command will only work if the string variable that we are trying to convert to numeric contains no nonnumeric characters. For example, if we have a variable coded as “0” or “1”, but in a given observation it was coded by mistake as “1b”, the destring command will not work. If we are dealing with small databases, it might be easy to visually identify which observation was wrongly coded. However, if we have a large database, containing lots of observations, this process might be difficult.
For this reason, I developed a Stata command called findnonnumeric. This command searches form nonnumeric characters within a string variable and lists the observations that have this issue. Instructions to use the command can be obtained by typing help findnonnumeric
Download findnonnumeric from my git repository: https://github.com/cauanebs/findnonnumeric
Installing ado files in Stata
Perform the following steps to install ado files in Stata:
- Open Stata
- Type personal and hit enter to discover the location of your personal ado folder
- Navigate to the personal ado folder (if after navigating there is no folder called personal, create one)
- Unzip the downloaded file into the personal ado folder