help for cprdenttype and cprdentcode(Roger Newson)

Converting CPRD entity string data of any enttype to numeric

cprdenttype # using filename [ , llookuplist(name) ldesclist(name) ]

cprdentcode [if] [in] , generate(stub)
lookuplist(string_list) [ desclist(string_list) dofile(filename) float ]

Description

The cprdenttype package is intended for use with datasets produced by the cprdutil package
to convert CPRD entity string data variables to numeric variables.
cprdenttype inputs an integer number, assumed to be a CPRD enttype (or entity type) value,
and a filename, assumed to be a Stata dataset produced by the cprd_entity module of cprdutil,
with one observation for each enttype value known to CPRD.
It outputs descriptive information about the entity type with the specified enttype value,
and, optionally, two local macros,
storing lists of CPRD lookups and descriptive labels for decoding the string data variables used by that enttype.
cprdentcode is used in test and additional clinical datasets,
produced by the cprd_test and cprd_additional modules of cprdutil,
respectively.
It inputs the lists specified by the local macros output by cprdenttype,
and uses them to input the string entity data variables in the datasets,
and to output a list of numeric variables with the correct formats, variable labels and/or value labels,
assuming that the test or additional clinical observations have the enttype value
originally specified by the user to cprdenttype.
cprdentcode requires the SSC package chardef in order to work.

Options for cprdenttype

llookuplist(name) specifies the name of a local macro,
to be set by cprdenttype to contain a list of lookups for the enttype specified.
The lookup list for an entity type specifies the way in which the string variables datai should be converted,
for values of i from 1 to the number of string data fields used by that enttype value.
The value "dd/mm/yyyy" specifies that the field will be input as a date in "DMY" format.
A 3-character name equal to the name of a CPRD XYZ lookup,
of the form "XYZ",
specifies that the field will be input as a number,
and then assigned the value label specified by the XYZ lookup
(if a correct dofile() option is specified to cprdentcode).
Other values, including the empty string "",
specify that the field will be input simply as a number,
with a default format and no value label.

ldesclist(name) specifies the name of a local macro,
to be set by cprdenttype to contain a list of descriptive labels for the specified enttype.
The descriptive label list for an entity type specifies the recommended variable labels
for the new numeric variables generated by coding from the string variables datai,
for values of i from 1 to the number of string data fields used by that enttype value.

Options for cprdentcode

generate(stub) specifies a prefix (or stub) to be used to name the generated numeric variables.
These generated variables will be named as stub1 to stubN,
where N is the number of string elements supplied in the lookuplist() option
(see below).
If the lookuplist() option is supplied as the value of the macro variable
specified by the llookuplist() option of cprdenttype,
then the number of list elements will be equal to the number of string data fielda
used by the enttype supplied to cprdenttype by the user.

lookuplist(string_list) specifies a list of quoted string values,
one for each of the data fields used by the entity type to be used,
usually supplied as the value of the local macro generated by tle llookuplist() option of cprdenttype.
The list will be used to specify the coding of the string variables to numeric variables.

desclist(string_list) specifies a list of quoted string values,
one for each of the data fields used by the entity type to be used,
usually supplied as the value of the local macro generated by tle ldesclist() option of cprdenttype.
The list will be used to specify variable labels for the newly generated numeric variables.

dofile(filename) specifies the name of an existing Stata do-file,
usually created using the dofile() option of the cprd_xyzlookup module of the cprdutil package.
This do-file is executed by cprdentcode,
and usually creates a long list of value labels,
some of which are then assigned to the numeric variables generated by cprdentcode.

float specifies that non-date variables may not have a higher precision than float.

Remarks

The Clinical Practice Research Datalink (CPRD) is a data warehouse
of information from primary-care practices in the British National Health Service (NHS).
The cprd_additional and cprd_test modules of the cprdutil package create datasets
containing a numeric variable enttype, which specifies a CPRD entity type,
and also containing string variables with names beginning with data,
such as data1 and data2.
These string variables contain information on CPRD entities, of a type indicated by enttype.
These entity types determine how the datai variables should be read,
in order to evaluate new numeric variables containing information on those entities.
For instance, entity type 1 is a blood pressure measurement,
and the datai variables in an observation whose enttype value is 1
contain information on the blood pressure measurement,
such as the systolic and diastolic values, the time of day when the measurement was made,
and the posture of the patient when the measurement was made.
The use of multiple entity types enables the same string variables
to be used to store different numeric data
in observations with different entity types.

A list of all the enttype values is usually stored in a Stata disk dataset,
created by the cprd_entity module of the cprdutil package.
This dataset has 1 observation per entity type,
and data on descriptive attributes of that entity type,
and also on the number of string data fields used by that entity type,
how these string fields should be converted to numeric variables,
and sensible variable labels for these numeric variables.
This information is extracted by cprdenttype
for the entity type value specified by the user,
and stored in saved results or local macros.
The basic descriptive information is output to the Stata log to inform the user.
The user can then input data to be converted,
and use cprdentcode to do the converting,
using the local macros set by cprdenttype.

Note that it is the user's responsibility to ensure
that cprdentcode is used sensibly,
on observations whose enttype value is the one specified by the user to cprdenttype.
However, it is easy (and saves space)
for the user to input into the memory only the observations with the correct enttype value,
before any conversion is done.

Examples

The following examples assume that the current folder has a sister folder ../cprddata containing a CPRD retrieval of text files,
and also a daughter folder ./dta where Stata datasets can be created.
The set-up section creates first a do-file xyzlookuplabs.do in the current folder,
to be run to define the CPRD value labels,
and then 3 Stata datasets entity, clinical, additional and test,
containing entity data, clinical-event data, additional clinical-event data records, and test data,
respectively.

Set-up:

. cprd_xyzlookup, txtdir("../cprddata/Lookups/TXTFILES") do(xyzlookuplabs.do, replace)

. cprd_entity using ../cprddata/Lookups/entity.txt, clear

. save ./dta/entity.dta, replace

. cprd_clinical using ../cprddata/Data/clinical.txt, clear dofile(xyzlookuplabs.do)

. save ./dta/clinical.dta, replace

. cprd_additional using ../cprddata/Data/additional.txt, clear dofile(xyzlookuplabs.do)

. save ./dta/additional.dta, replace, replace

. cprd_test using ../cprddata/Data/test.txt, clear dofile(xyzlookuplabs.do)

. save ./dta/test.dta, replace

The following example starts by using cprdenttype to create 2 local macros LL and LD,
containing the lookups list and the descriptive label list, respectively,
for the enttype value 4 ("Smoking").
It then inputs additional clinical data records with enttype equal to 4,
and uses cprdentcode to generate a list of numeric variables, numbered ad_1 to ad_6,
with variable labels, value labels and formats defined by the do-file generated earlier,
and by the lists in the 2 local macros generated earlier.
The user may tabulate, summarize and graph these variables
to find out about the distributions of smoking-status data.

. clear

. cprdenttype 4 using ./dta/entity, llookuplist(LL) ldesclist(LD)

. use ./dta/additional if enttype==4, clear

. describe, full

. cprdentcode, generate(ad_) lookuplist(`LL') desclist(`LD') dofile(xyzlookuplabs.do)

The following example also starts by using cprdenttype to create 2 local macros LL and LD,
this time containing the lookups list and the descriptive label list, respectively,
for the enttype value 163 ("Serum cholesterol").
It then inputs test data records with enttype equal to 163,
and uses cprdentcode to generate a list of numeric variables, numbered td_1 to td_7,
with variable labels, value labels and formats defined by the do-file generated earlier,
and by the lists in the 2 local macros generated earlier.
This time, we save space by using the float option
to prevent double-precision variables.
The user may tabulate, summarize and graph these variables
to find out about the distributions of serum cholesterol data.

. clear

. cprdenttype 163 using ./dta/entity, llookuplist(LL) ldesclist(LD)

. use ./dta/test if enttype==163, clear

. describe, full

. cprdentcode, generate(td_) lookuplist(`LL') desclist(`LD') dofile(xyzlookuplabs.do) float

Note that cprdutil modules require the SSC packages
keyby, addinby, chardef, lablist, and intext
to be installed in order to work.
It is also a good idea to call cprdenttype before inputting any large datasets,
because otherwise the large datasets will be temporarily preserved
when the smaller entity dataset is input,
creating a lot of work.

Saved results

cprdenttype saves the following results in r():

Scalars

r(enttype) the user-specified entity type

r(data_fields) the number of data fields used by the entity type

Macros

r(description) description of entity type

r(filetype) type of data file ("Test" or "Clinical") using the entity type

r(category) broad category for entity type

r(lookuplist) lookup list for data fields

r(desclist) descriptive label lists for data fields

cprdentcode saves the following results in r():

Macros

r(newvars) list of generated numeric output variables

cprdentcode also saves, for each generated variable,
the variable characteristic varname[lookup],
containing the CPRD lookup rule used for the generated variable.
This may be a 3-character value label name,
or a CPRD date format specification such as "dd/mm/yyyy",
or a specification such as "medical dictionary",
indicating that the generated variable refers to a medical code in the CPRD medical dictionary.

Author

Roger Newson, Imperial College London, UK.

Email: r.newson@imperial.ac.uk

Also see

Help: Clinical Practice Research Datalink (CPRD)

cprdutil, keyby, addinby, chardef, lablist, intext if installed