Skip to main content

3.7 Changing value format from alphanumerical (text) into numerical

Many variables available through microdata.no contain alphanumerical values (text format). However, the command destring can convert such values into numerical format. By default, the variable will be overwritten by the new format (a separate variable will not be created:

destring <variable/variable list> [, <options>]

If there are values containing non-numerical characters, e.g. ,, ., -, nkr, $, then the conversion will not complete unless the options force or ignore() are used.

The option force will force the system to convert into numerical values no matter what, where values containing non-numerical characters will be given the value for missing value: sysmiss

The option ignore() makes it possible to define which characters/symbols to be ignored during the conversion process. This could be useful for values formatted by hyphens, commas, thousands separators etc. The following example will ignore dots, commas and hyphens that occur in values for the variable var1:

destring var1, ignore('.,-')

Alphanumerical values containing commas as decimal separators ('2,1', '10000,00' etc) may be converted directly into numerical values while keeping the decimals. By doing so, the converted values will be using dots as decimal separator. The option dpcomma can be used for such operations.

For more information on the use of destring, e.g. overview of all available options, use the help destring command.