Stata 15 help for icd9

[D] icd9 -- ICD-9-CM diagnosis codes


Verify that variable contains defined codes

icd9 check varname [if] [in] [, any list generate(newvar)]

Clean variable and verify format of codes

icd9 clean varname [if] [in] [, dots pad]

Generate new variable from existing variable

icd9 generate newvar = varname [if] [in], category

icd9 generate newvar = varname [if] [in], description [long end]

icd9 generate newvar = varname [if] [in], range(codelist)

Display code descriptions

icd9 lookup codelist

Search for codes from descriptions

icd9 search ["]text["] [["]text["] ...] [, or]

Display ICD-9 code source

icd9 query

codelist is

icd9code (the particular code) icd9code* (all codes starting with) icd9code/icd9code (the code range)

or any combination of the above, such as 001* 018/019 E* 018.02. icd9codes must be typed with leading 0s. For example, type 001; typing 1 will result in an error.


Data > ICD codes > ICD-9


icd9 is a suite of commands for working with ICD-9-CM diagnosis codes from the 16th version (effective October 1998) to the 32nd version. To see the current version of the ICD-9-CM diagnosis codes and any changes that have been applied, type icd9 query.

icd9 check, icd9 clean, and icd9 generate are data management commands. icd9 check verifies that a variable contains defined ICD-9-CM diagnosis codes and provides a summary of any problems encountered. icd9 clean standardizes the format of the codes. icd9 generate can create a binary indicator variable for whether the code is in a specified set of codes, a variable containing a corresponding higher-level code, or a variable containing the description of the code.

icd9 lookup and icd9 search are interactive utilities. icd9 lookup displays descriptions of the codes specified on the command line. icd9 search looks for relevant ICD-9-CM diagnosis codes from key words given on the command line.


Options are presented under the following headings:

Options for icd9 check Options for icd9 clean Options for icd9 generate Options for icd9 search

Options for icd9 check

any tells icd9 check to verify that the codes fit the format of ICD-9-CM diagnosis codes but not to check whether the codes are defined.

list specifies that icd9 check list the observation number, the invalid or undefined ICD-9-CM diagnosis code, and the reason the code is invalid or whether it is an undefined code.

generate(newvar) specifies that icd9 check create a new variable containing, for each observation, 0 if the observation contains a defined code or is missing. Otherwise, it contains a number from 1 to 10. The positive numbers indicate the kind of problem and correspond to the listing produced by icd9 check.

Options for icd9 clean

dots specifies that the period be included in the final format. If dots is not specified, then all periods are removed.

pad specifies that icd9 clean pad the codes with spaces, front and back, to make the (implied) dots align vertically in listings. Specifying pad makes the resulting codes look better when used with most other Stata commands.

Options for icd9 generate

category, description, and range(codelist) specify the contents of the new variable that icd9 generate is to create. You do not need to icd9 clean varname before using icd9 generate; it will accept any supported format or combination of formats.

category creates a new variable that contains ICD-9-CM diagnosis category codes. The resulting variable may be used with the other icd9 subcommands. For diagnosis codes, the category code is the first three characters, except for E-codes, when it is the first four characters.

description creates newvar containing descriptions of the ICD-9-CM diagnosis codes.

long is for use with description. It specifies that the code be prepended to the text describing the code.

end modifies long (specifying end implies long) and places the code at the end of the string.

range(codelist) creates a new indicator variable equal to 1 when the ICD-9-CM diagnosis code is in the range specified, equal to 0 when the ICD-9-CM diagnosis code is not in the range, and equal to missing when varname is missing.

Option for icd9 search

or specifies that ICD-9-CM diagnosis codes be searched for descriptions that contain any word specified with icd9 search. The default is to list only descriptions that contain all the words specified.


View log of changes made to the list of ICD-9 codes since icd9 was implemented in Stata . icd9 query

Display a description of code 526.4 . icd9 lookup 526.4

Look up a range of codes . icd9 lookup 526/527

Search for codes containing the words jaw and disease . icd9 search jaw disease

Setup . webuse nhds2010

Clean dx1 diagnosis code variable . icd9 clean dx1

Create variable main1 containing category codes for dx1 . icd9 generate main1 = dx1, category

Attempt to clean dx3 diagnosis code variable; will return error . icd9 clean dx3

Flag observations containing invalid codes . icd9 check dx3, generate(prob)

Stored results

icd9 check stores the following in r():

Scalars r(e#) number of errors of type # r(esum) total number of errors

icd9 clean stores the following in r():

Scalars r(N) number of changes

icd9 lookup stores the following in r():

Scalars r(N) number of codes found

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index