
Variable name type format label variable label If there had been any numeric variables in theĭataset, they would remain unchanged. Since these variables had characters in them, the destring command Numeric, except for race, gender and schtyp. Science has all characters numeric replaced as byteĬommand below, the destring command converted all of the variables to Read has all characters numeric replaced as byte Schtyp contains non-numeric characters no replace Race contains non-numeric characters no replace Gender contains non-numeric characters no replace Id has all characters numeric replaced as int Of syntax loads the dataset again, so that we are starting with a datasetĬontaining only string variables again. Let’s try using the destring command and see how it works. Translates the values held as strings, where s is the variable containingĪ second method of achieving the same result is the command destring.

Generates a new variable read_n that is equal to the value of the number The first line of syntax reads in the dataset shown above. That translates numeric values stored as strings into numeric values Stata can recognizeĪs such. One method of converting numbers stored as strings into numerical variables is to use 85 m 1 pub 55 53 Converting string variables with numeric values Even so, because the variable is defined as str2, Stata cannot performĪny kind of numerical analysis of the variable science. Although the variable science isĭefined as str2, you can see from the list below that it contains See what the strings stored in these variables look like. Now that we know the variables are string variables, we can use the list command to Subset of the High School and Beyond data file with all of the variables as stringīelow, the variables are all defined as string variables (e.g., science

Strings, and the goal is to assign each value the string takes on to a numericĪll of the examples on this page use the same dataset, so let’s startīy examining the data. Then we will address the case where the string variables actually contain Numerical values that are stored as strings. You cannot get means, you cannotĭo a regression, you cannot do an ANOVA, etc… Sometimes the dataset contains May contain numeric values, but if they are defined as type string, thereĪre very few things you can do to analyze the data. Of the variables defined as strings, that is, character variables. There may be times that you receive a file that has many (or all)
