*! version 1.1 13jan2015

Title

mycd10 -- ICD-10 diagnostic and procedure codes

Syntax

Prepare WHO ICD-10 diagnosis code data for use with mycd10

mycd10 prepare using WHOfile

mycd10 prepare codes using WHOfile

mycd10 prepare chapters using WHOfile

mycd10 prepare blocks using WHOfile

Verify that variable contains defined codes

{mycd10|mycd10p}
check varname
[,
any
list
generate(newvar)]

Verify and clean variable

mycd10
clean varname
[,
dots
pad]

mycd10p
clean varname
[,
pad]

Generate new variable from existing variable

{mycd10|mycd10p} generate newvar = varname, main

{mycd10|mycd10p} generate newvar = varname, description[long end]

mycd10 generate newvar = varname, chapter[long end]

mycd10 generate newvar = varname, block[long end]

{mycd10|mycd10p} generate newvar = varname, range(icd10rangelist)

Display code descriptions

{mycd10|mycd10p} lookup icd10rangelist

{mycd10|mycd10p} lookup codes icd10rangelist

mycd10 lookup chapters icd10chapterlist

mycd10 lookup blocks icd10blockrangelist

Search for codes from descriptions

{mycd10|mycd10p}
search
["]text["]
[["]text["] ...]
[,
or]

Display ICD-10 code source

{mycd10|mycd10p}
query

where icd10rangelist is

icd10code (the particular code)

icd10code* (all codes starting with icd10code)

icd10code/icd10code (the code range)

or any combination of the above, such as A01* C18/C19 Q* N28.9.

where icd10chapterlist is any valid Stata numlist

where icd10blockrangelist is

icd10block (the particular block)

icd10block* (all blocks starting with icd10block)

icd10block/icd10block (the block range)

or any combination of the above, such as A* B60/B99 C02.

mycd10 is for use with ICD-10 diagnostic codes, and mycd10p for use with
procedure codes. The two commands' syntaxes parallel each other. myicd10 and
myicd10p are acceptable synonyms for mycd10 and mycd10p, respectively.

Description

mycd10 and mycd10p help when working with ICD-10 codes.

ICD-10 diagnostic codes are maintained by the World Health Organization. The system
was developed in 1990 and released in 1994. It has been in use in several countries since
the late 1990s. Because of licensing restrictions the ICD-10 lookup data set cannot
be included with mycd10. See the discussion of mycd10 prepare below for more details.

The ICD-10 Procedure Coding System (ICD-10-PCS) was developed by the Centers for
Medicare and Medicaid Services (CMS) and 3M Health Information Systems in 1993.
It was released in 1998 as an eventual replacement for the ICD-9-CM procedure code system and
it is updated annually.

ICD-10 codes come in two forms: diagnostic codes and procedure codes. In this
system, A00 (cholera) and S01.2 (Open wound of nose) are examples of
diagnostic codes, although some people write (and datasets record) S012
rather than S01.2. Also, 005 (Central Nervous System, Destruction) and 00500ZZ
(Destruction of Brain, Open Approach) are are examples of procedure codes.
mycd10 understand both ways of recording codes. Periods are not allowed
in ICD-10 procedure codes. mycd10 does not (yet) support optional code qualifiers.

Important note: What constitutes a valid ICD-10 code changes over time.
For the rest of this help file, a defined code is any code
that is either currently valid, was valid at some point since the 2008 version,
or has meaning as a grouping of codes. For example, the diagnosis code A00, though not valid on its
own, is useful because it denotes cholera. It is kept as a defined code
whose description ends with an asterisk (*). Unlike Stata's icd9[p]
command, there is no capability (yet) in mycd10[p] to determine whether
and when certain codes have been added, changed, or removed.

mycd10 and mycd10p parallel each other; mycd10 is
for use with diagnostic codes, and mycd10p for use with procedure codes.

mycd10
prepare
reads an ICD-10 lookup dataset downloaded from WHO and creates a Stata version called
mycd10_cod.dta which contains the variables required for use with mycd10.
Go to http://www.who.int/about/licensing/classifications/en/,
click on "Register for non-commercial use" at the bottom of the page, and
follow the instructions. You will have to create a user account, complete
a form regarding how you will use the ICD-10 data, and agree to the non-commercial
research license. Once that process is complete, download the ICD-10 2nd Edition in
plain text tabular form, then run mycd10 prepare, providing the file name of the
downloaded file (probably codes.txt). This command also creates a data set called mycd10_raw.dta, which contains
all of the variables contained in the file from WHO. Both data sets are stored
in the same directory as the mycd10 program.

mycd10
prepare codes
is the same as
mycd10
prepare

mycd10
prepare chapters
reads the ICD-10 lookup dataset that contains the list of chapters and chapter descriptions. This file is normally included in the
download from WHO and will probably be named chapters.txt. This command must be run before using mycd10 generate, chapter or
mycd10 lookup chapter. Note that chapters and chapter descriptions are only relevant for ICD-10 diagnosis codes, not
ICD-10 procedure codes.

mycd10
prepare blocks
reads the ICD-10 lookup dataset that contains the list of block groups and block group descriptions. This file is normally included in the
download from WHO and will probably be named blocks.txt. This command must be run before using mycd10 generate, block or
mycd10 lookup block. Note that blocks and block group descriptions are only relevant for ICD-10 diagnosis codes, not
ICD-10 procedure codes.

mycd10[p]
check verifies that existing variable varname contains defined
ICD-10 codes. If not, mycd10[p] check provides a full
report on the problems.
mycd10[p] check is useful for tracking down problems when any
of the other mycd10[p] commands tell you that the
"variable does not contain
ICD-10 codes". mycd10[p] check
verifies that each recorded code actually exists in the defined
code list.

mycd10[p]
clean also verifies that existing variable varname contains
defined ICD-10 codes and, if it does, mycd10[p] clean modifies
the variable to contain the codes in either of two standard formats.
All mycd10[p] commands
work equally well with cleaned or uncleaned codes. There are several ways of
writing the same ICD-10 code, and mycd10[p] clean is designed
to ensure consistency and to make subsequent output look better.

mycd10[p]
generate
produces new variables based on existing variables containing
(cleaned or uncleaned) ICD-10 codes.
mycd10[p] generate, main
produces newvar containing the main code (the first three characters, also known as the block).
mycd10[p] generate, description
produces newvar containing a textual description of the ICD-10 code, mycd10 generate, chapter
produces newvar containing a textual description of the the chapter corresponding
to the ICD-10 diagnosis code, and mycd10 generate, block
produces newvar containing a textual description of the the block group corresponding to the ICD-10 diagnosis code.
mycd10[p] generate, range()
produces numeric newvar containing 1 if varname records an ICD-10
code in the range listed and 0 otherwise.

mycd10[p]
lookup
and mycd10[p] search
are utility routines that are useful interactively.
mycd10[p] lookup simply displays descriptions of the codes
specified on the command line, so to find out what
diagnosis code Q30.1 means, you can type mycd10 lookup q30.1. The
data that you have in memory are irrelevant -- and remain
unchanged -- when you use
mycd10[p] lookup.

mycd10[p] lookup codes is the same as
mycd10[p] lookup.

mycd10 lookup chapters displays descriptions of the chapters
specified on the command line. Since chapters are integers, any valid Stata numlist
can be specified. For example, to find out what chapters 19 and 20 are, type mycd10 lookup chapters 19/20.

mycd10 lookup blocks displays descriptions of the blocks
specified on the command line. For example, to find out what block group block Q30 is in, type mycd10 lookup block Q30.
Note that since block groups are themselves ranges of blocks, if you specify a range of blocks to look up,
all block groups that overlap the specified range will be returned. For example, mycd10 lookup blocks B60/B70
will return the descriptions for block groups B50-B64 and B65-B83.

mycd10[p] search is similar to
mycd10[p] lookup (and lookup codes), except that it turns the problem around;
mycd10[p] search looks for relevant ICD-10 codes from the
description given on the command line. For instance, you could type
mycd10 search liver or mycd10p search liver to obtain a list of
codes containing the word "liver".

mycd10[p]
query
displays the identity of the source from which the ICD-10 codes
were obtained and the textual description that mycd10[p] uses.

ICD-10 diagnosis codes are commonly written two ways: with and without periods.
For instance, you can write A00 and J348, or you can write A00. and J34.8.
With procedure codes, however, you can write 005 and 00500ZZ, but you cannot use periods.
The mycd10 command does not care which syntax you use or even whether
you are consistent. mycd10p does not allow the use of periods.
Case is irrelevant in mycd10[p]: q309, q30.9, Q309, and Q30.9
are all equivalent in mycd10 and 00500zz and 00500ZZ are equivalent in
mycd10p. Codes may be recorded with or without leading and
trailing blanks.

Options for mycd10[p] check

any tells mycd10[p] check to verify that the codes
fit the format of ICD-10 codes but not to check whether the codes are
actually defined. This makes mycd10[p] check run faster. For
instance, diagnostic code D33.5 (or D335, if you prefer) looks valid,
but there is no such ICD-10 code. Without the any option, D33.5
would be flagged as an error. With any, D33.5
is not an error.

list reports any invalid codes that were found in the data
by mycd10[p] check.
For example, A1, A1.1.1, and perhaps D33.5, if any is not
specified, are to be individually listed.

generate(newvar) specifies that mycd10[p]
check create new variable newvar containing, for each
observation, 0 if the code is defined and a number from 1 to 11 otherwise. The
positive numbers indicate the kind of problem and correspond to the listing
produced by mycd10[p] check. For instance, in mycd10 9 means that the
code could be valid, but it turns out not to be on the list of defined codes.

Options for mycd10[p] clean

dots specifies whether periods are to be included in the final format.
Do you want the diagnostic codes recorded, for instance, as G958 or G95.8?
Without the dots option, the G958 format would be used.
With the dots option, the G95.8 format would be used. This option is not valid
in mycd10p

pad specifies that the codes are to be padded with spaces, front
and back, to make the codes line up vertically in listings. Specifying
pad makes the resulting codes look better when used with most other
Stata commands.

Options for mycd10[p] generate

main, description, chapter, block, and range(icd10rangelist)
specify what mycd10[p] generate is to calculate. chapter and block
are not valid with mycd10p. varname always specifies a variable containing ICD-10 codes.

main specifies that the main code be extracted from the
ICD-10 code. For procedure codes, the main code is the first three characters (although
this is not an official designation in the ICD-10 procedure code system).
For diagnostic codes, the main code is usually the first three characters
(the characters before the dot if the code has dots). In any case,
mycd10[p] generate does not care whether the code is padded
with blanks in front or how strangely it might be written; mycd10[p]
generate will find the main code and extract it. The resulting variable
is itself an ICD-10 code and may be used with the other mycd10[p]
subcommands. This includes mycd10[p] generate, main.

description creates newvar containing descriptions of the
ICD-10 codes.

chapter creates newvar containing descriptions of the
chapters corresponding to each ICD-10 diagnosis code. (Requires Stata 10 or above)

block creates newvar containing descriptions of the
block groups corresponding to each ICD-10 diagnosis code. (Requires Stata 10 or above)

long is for use with description, chapter, and block. It specifies that the new
variable, in addition to containing the text describing the code, chapter, or block,
also contain the code, chapter number, or block group, too. Without long, newvar in an observation
might contain "Injury of bronchus", "Injury, poisoning and certain other consequences of external causes",
or "Injuries to the thorax". With long, it would contain
"S27.4 Injury of bronchus", "19) Injury, poisoning and certain other consequences of external causes",
or "S20-S29) Injuries to the thorax".

end modifies long (specifying end implies long)
and places the code at the end of the string: "Injury of bronchus S27.4", or
"Injury, poisoning and certain other consequences of external causes (19)",
or "Injuries to the thorax (S20-S29)".

range(icd10rangelist) allows you to create indicator variables
equal to 1 when the ICD-10 code is in the inclusive range specified.

Option for mycd10[p] search

or specifies that ICD-10 codes be searched for entries
that contain any word specified after mycd10[p]
search. The default is to list only entries that contain all the words
specified.

Examples

Prepare data set for use with mycd10

. mycd10 prepare using C:\Downloads\codes.txt

Display a description of code C15.9

. mycd10 lookup C15.9

Look up a range of codes

. mycd10 lookup C15/C16

Display a description of chapter 19

. mycd10 lookup chapter 19

Look up a range of chapters

. mycd10 lookup chapter 19/20

Display a description of the block group containing C15

. mycd10 lookup block C15

Look up a range of blocks

. mycd10 lookup block B50/B70

Search for codes containing the words jaw and disease

. mycd10 search jaw disease

Attempt to clean diag1 diagnostic code variable

. mycd10 clean diag1

Flag observations containing invalid codes

. mycd10 check diag1, gen(prob)

List flagged observations

. list patid diag1 if prob

Clean diag2 diagnostic code variable

. mycd10 clean diag2

Add periods to diag2 variable

. mycd10 clean diag2, dots

Clean proc1 procedure code variable and add spaces for padding

. mycd10p clean proc1, pad

Check that proc1 contains valid procedure codes

. mycd10p check proc1

Create variable tp1 containing descriptions of codes in proc1

. mycd10p generate tp1 = proc1, description

Create variable chp1 containing descriptions of chapters corresponding to codes in dx1

. mycd10 generate chp1 = dx1, chapter

Create variable blk1 containing descriptions of block groups corresponding to codes in dx1

. mycd10 generate blk1 = dx1, block

Create variable main1 containing main codes

. mycd10 generate main1 = diag2, main

Saved results

mycd10 and mycd10p save the following in r():

Scalars

r(e#) number of errors of type #

r(esum) total number of errors

Acknowledgements

The code and help for mycd10 is borrowed almost entirely from the Stata icd9
command and it is expected that this program will be retired as soon as StataCorp
is able to produce their own version. Thanks also to Statalist members Sara Glick,
Tom Weichle, and Matthew Barclay, who (unwittingly) encouraged this effort. Thanks to
Joanna Davies who inspired the addition of the functionality for chapter and block
group descriptions. Finally, thanks in advance to the Stata user community for
providing feedback. This program will no doubt benefit from extensive use with
real-life data sets.

Author

Joseph Canner

Johns Hopkins University School of Medicine

Department of Surgery

Center for Surgical Trials and Outcomes Research

Email jcanner1@jhmi.edu