Summary

Working with dataset coding and data quality checks

From: Smoking Behaviour Study Dataset

Working with dataset coding and data quality checks

This lesson shows how to turn coded variables into analysis-ready values and how to run simple quality checks using the metadata in Copy of Smoking Data 2(1).

1. Identify the variables and their types

In the Copy of Smoking Data 2(1) workbook, the Rawdata sheet contains these variables:

  • Age
  • Alcohol
  • AgeOnset
  • Gender
  • Smoking

The ListVariables sheet states that:

  • Age is a scale variable.
  • Alcohol is nominal.
  • AgeOnset is nominal.
  • Gender is nominal.
  • Smoking is a scale variable.

This matters because coded nominal variables should be translated into labels before analysis, while scale variables should be checked mainly for valid numeric ranges.

2. Translate coded values into labels

The coding rules are given in the ListVariables and Source sheets of Copy of Smoking Data 2(1).

Alcohol

  • 0 = None to low levels
  • 2 = Moderate to High levels

So an analysis-ready version of Alcohol would replace the numeric code with these category labels.

A basic check is important here: the metadata lists valid values 0 to 2, but the value labels shown only define 0 and 2. That means code 1 would fall inside the stated range but has no label in the provided metadata. In the displayed raw rows, Alcohol appears as 0.00 or 1.00, so this inconsistency should be flagged for review against the metadata in Copy of Smoking Data 2(1).

AgeOnset

  • 1 = 0 to 30 yrs age
  • 2 = 31 and older

This variable is already grouped. To make it analysis-ready, convert the codes into clear category names such as:

  • 1 - 0 to 30 yrs age
  • 2 - 31 and older

Gender

  • 1 = Male
  • 2 = Female

For reporting, it is usually clearer to use the labels Male and Female instead of the numeric codes.

3. Keep scale variables numeric

According to the Source sheet in Copy of Smoking Data 2(1):

  • Age has a valid range of 16 to 68.83.
  • Smoking has a valid range of 1.7729 to 9.9717.

These should remain numeric for analysis, but their values should be checked against the allowed ranges.

4. Perform basic data quality checks

When preparing the dataset, compare the raw values with the metadata from Copy of Smoking Data 2(1).

Range checks

  • Check whether every Age value falls between 16 and 68.83.
  • Check whether every Smoking value falls between 1.7729 and 9.9717.

From the displayed rows, examples such as Age 16.00, 67.00, and 68.83 fit the stated range. Smoking values shown, such as 1.77, 5.95, 8.90, and 9.97, align with the stated minimum and maximum when read to two decimal places, but exact checking should use the full metadata limits.

Category-value checks

  • AgeOnset should only contain 1 or 2.
  • Gender should only contain 1 or 2.
  • Alcohol should be checked carefully because the metadata is internally inconsistent: the variable range says 0 to 2, but the listed labels only define 0 and 2.

In the displayed rows, AgeOnset uses 1.00 and 2.00, and Gender uses 1.00 and 2.00, which matches the metadata. Alcohol includes 1.00 in many displayed rows, so those values should be treated as a coding issue that needs clarification from the metadata source.

Consistency checks

A consistency check asks whether the raw data matches the documentation.

  • AgeOnset is consistent with the metadata because its observed values match the documented codes 1 and 2.
  • Gender is consistent with the metadata because its observed values match the documented codes 1 and 2.
  • Alcohol is not fully consistent with the metadata shown, because observed raw values include 1.00 while the documented value labels only show 0 and 2.

This is exactly the kind of issue a basic quality review should detect before analysis begins.

5. Example of analysis-ready recoding

Using the metadata in Copy of Smoking Data 2(1), you could prepare variables like this:

  • Alcohol_label: 0 = None to low levels; 2 = Moderate to High levels; 1 = unresolved code needing review
  • AgeOnset_group: 1 = 0 to 30 yrs age; 2 = 31 and older
  • Gender_label: 1 = Male; 2 = Female

This keeps the original codes available while adding readable variables for tables and analysis.

6. Practical workflow

  1. Read the variable names from Rawdata.
  2. Use ListVariables and Source to find each variable’s scale type and code labels.
  3. Recode nominal variables into readable category labels.
  4. Check numeric variables against documented minimum and maximum values.
  5. Check categorical variables for undocumented or impossible codes.
  6. Flag any mismatch between raw data and metadata before analysis.

7. Key lesson

The main skill is not just recoding values, but recoding them according to the metadata and verifying that the data actually follows that metadata. In Copy of Smoking Data 2(1), AgeOnset and Gender can be translated cleanly, while Alcohol requires extra attention because the observed code 1.00 is not explained by the provided value labels. That makes data quality checking an essential step in producing analysis-ready variables.