help for cprdcribs(Roger Newson)

Template do-files for inputting CPRD datasets into Stata

The cprdcribs package is a set of template (or crib) do-files
for inputting text datasets
produced by the Clinical Practice Research Datalink (CPRD),
and outputting a core set of Stata datasets for a CPRD database,
together with a do-file
to create the full set of Stata value labels for the database.
The core datasets are the non-XYZ-lookup datsets for a CPRD database,
together with a dataset with 1 observation per practice,
a dataset with 1 observation per patient,
and a dataset with 1 observation per patient per calendar year of observation by CPRD.
The user may modify the template do-files for the user's own requirements,
and/or produce additional do-files to input other kinds of CPRD text datasets into Stata.
The template do-files may be modified by the user.
They include a do-file to produce the lookups,
a do-file to produce the practice dataset,
a do-file to produce the patient dataset,
a do-file to produce the patient-years dataset,
and a master do-file that calls the other do-files in a sensible order,
using the SSC package dolog.
The do-files of the cprdcribs package use the SSC package cprdutil.
It is probably a good idea to install all of Roger Newson's Stata packages before using these do-files.
This installation can be done using one of the instasisay packages,
downloadable from Roger Newson's website.

Template do-files distributed with cprdcribs

lookups.do inputs CPRD lookup tables from folders containing text files specifying these lookups.
There are two kinds of lookups,
namely XYZ lookups (each of which is converted into a Stata value label of the same name),
and non-XYZ lookups (each of which is converted into a Stata dataset of the same name).
The value labels corresponding to the XYZ lookups are specified in an output Stata do-file
named xyzlookuplabs.do,
which can be run from other do-files to create the whole set of value labels.
The datasets corrsponding to the non-XYZ lookups
can be merged into other Stata datasets, using the merge command of official Stata,
or the SSC package addinby.
The input text files for the XYZ lookups and non-XYZ lookups
must exist in folders specified by the user,
and the output Stata datasets specifying the non-XYZ lookups
are created in another folder specified by the user.
Usually, the user needs to modify lookups.do,
so that the correct folders are specified.

practice.do inputs a text dataset with 1 row per primary-care practice,
and outputs a Stata dataset with 1 observation per primary-care practice.
Both of these files must be specified by the user,
who must usually modify practice.do.

patient.do inputs a text dataset with 1 row per patient,
and a Stata dataset with 1 observation per practice,
and outputs a Stata dataset with 1 observation per patient.
All of these files must be specified by the user,
who must usually modify patient.do.

patientyear.do inputs a Stata dataset with 1 observation per patient,
which might be produced using patient.do.
It outputs a dataset with 1 observation per patient per calendar year
in which the patient was observed by CPRD,
and data on the age (in years) attained by that patient in that calendar year,
and on the exposure time (in days)
in which that patient was observed by CPRD in that calendar year.
This dataset is created using the SSC package expgen.
It might be enlarged by merging in datasets
with 1 observation per patient per calendar year
and data on event counts.
The user can then fit Poisson models, with event count as the outcome,
age as a possible covariate or factor,
and Huber variances clustered by patient or by practice.
Users may modify patientyear.do
to produce a dataset with 1 observation per United Kingdom fiscal year
(from 01 April to 31 March),
and/or to include patient age at the start of the year of observation
as a possible model covariate or factor.

create.do is the master do-file.
It uses the SSC package dolog
to call the servant do-files
lookups.do, practice.do, patient.do and patientyear.do,
in that order,
creating output Stata log files and output Stata datasets.
The order is important,
because patientyear.do uses output created by patient.do,
which uses output created by practice.do,
which uses output created by lookups.do.
The user may modify create.do
to use dolog again,
calling other do-files to produce other CPRD datasets,
with observations corresponding to other CPRD things,
such as therapy prescriptions or clinical events.

Remarks

The Clinical Practice Research Datalink (CPRD) is a data warehouse of information
from primary-care practices in the British National Health Service.
Tab-delimited text data files of various types can be retrieved,
containing data on things known to these practices,
such as practices, patients, staff members, clinical events, additional details on clinical events,
consultations, immunisations, referrals, tests, and prescribed therapies.

The cprdcribs package is intended to help the user to create sensible CPRD Stata databases,
using sensible do-files executed in a sensible order.
Usually, a do-file is called using the SSC package dolog,
and produces a Stata log file of the same name in the same folder,
and a Stata dataset of the same name that may be in a sub-folder.
It is usually a good idea to have a master do-file like create.do,
because do-files executed later may use output from do-files executed earlier,
and because a large and complicated CPRD database may take a long time to be created,
especially if it includes a large number of datasets,
with observations corresponding to things other than patients or practices.
It is not uncommon for a sequence of do-files creating a CPRD database
to be run overnight.
When this happens,
it is useful to be able to call the master do-file at the end of the working day,
so the master do-file can call the servant do-files overnight,
in the correct order at the correct times.

The master do-file is usually run using a do command,
instead of the dolog package.

Examples

The following example create a core CPRD Stata database,
including lookup datasets, a practice dataset, a patient dataset,
and a patient-year dataset.

. dolog lookups

. dolog practice

. dolog patient

. dolog patientyear

The following example does the same thing by calling create.do to call the other do-files.
It may do other things afterwards,
such as creating other datasets and maybe analysing the data,
if the user has modified create.do to run other do-files.

. do create

Saved results

The do-files lookups.do, practice.do and patient.do
all contain global commands,
which set global macros to specify the folders used for input
of a retrieval of CPRD text files.
Such retrievals usually are provided as a root folder,
containing subfilders Data and Lookups.
The Data folder usually contains the data files.
The Lookups folder usually contains the non-XYZ lookup files,
and also a sub-folder TXTFILES,
containing the XYZ lookup files.
The do--files lookups.do, practice.do and patient.do,
in their unmodified form,
attempt to create all Stata .dta files in the subfolder ./dta,
and set the values of the following global macros:

Macros

CPRDDATA Root folder for the CPRD retrieval

It is usually good practice to store folder locations in macros.
This is because users frequently re-arrange databases,
implying that folder locations have to be changed.
This is easier to do if the folder location is only specified once per do-file,
near the top of the do-file.

lookups.do also creates an output do-file xyzlookuplabs.do,
in the current directory,
which can then be run to create Stata value labels specified by the XYZ lookups.

Author

Roger Newson, Imperial College London, UK.

Email: r.newson@imperial.ac.uk

Also see

Help: Clinical Practice Research Datalink (CPRD)

keyby, addinby, lablist, chardef, intext, expgen,
cprdutil, dolog, instasisay if installed