Part 1 · Module 3

Understanding Variables and Data Types

Learn how to identify variable roles, classify categorical and numerical data, and choose suitable summaries for medical research.

Learning outcomes

After completing this lecture, you should be able to:

  • Define an observation, variable and value using examples from medical research.
  • Distinguish a variable's statistical role from its data type.
  • Classify variables as categorical or numerical and recognise common subtypes.
  • Select suitable descriptive summaries and displays for different data types.
  • Identify coding and data-quality problems that can change the meaning of a variable.

Overview

Medical datasets contain diagnoses, laboratory measurements, symptom grades, event counts and dates. Before choosing a summary, graph or statistical analysis, a researcher must understand what each item means and how it was recorded.

A variable is a characteristic that can take different values across people, specimens, visits, hospitals or other units of observation. Examples include age, smoking status and 30-day mortality. A variable’s role in a study must be considered separately from its data type.

This lecture classifies variables into categorical and numerical data and shows how classification influences data collection, checking, summarisation and analysis. Scales of measurement are developed in the next lecture.

Why this matters

Incorrect classification can lead to a misleading summary or an inappropriate analysis. The mean of identification numbers is meaningless. Treating the codes 1, 2 and 3 for smoking status as measured quantities creates a false numerical order. Converting a laboratory result into “normal” and “abnormal” may discard important information.

Classification begins with clinical meaning, not with how a spreadsheet or statistical program stores the values. Medical statistics textbooks distinguish categorical information from numerical measurements and counts because they support different descriptions and analyses [1], [2] and [3].

Key concepts

Observation, variable and value

An observation is the unit on which information is recorded. In the pneumonia study, the primary unit of observation is one participant.

A variable is a characteristic recorded for each observation. oxygen_saturation_pct is one variable.

A value is the recorded information for one observation on one variable. An oxygen saturation of 88% is one value.

In a conventional participant-level dataset, each row represents one participant, each column represents one variable and each cell contains one value. With repeated visits, specimens or measurements, one person may contribute several rows, and that relationship must be explicit.

A variable has both a role and a type

A variable’s role describes how it contributes to the research question. Its type describes the form of information it contains.

Common roles include:

  • outcome variable: the event or characteristic the study seeks to describe, explain or predict;
  • explanatory variable: an exposure, treatment, patient characteristic or grouping factor examined in relation to the outcome;
  • identifier: a code that distinguishes records but is not analysed as a clinical quantity;
  • timing variable: a date, clock time or duration; and
  • derived variable: a value calculated from other variables using a predefined rule.

In the pneumonia study, death_30d is the outcome and is binary categorical. crp_mg_l is an explanatory variable and is numerical. patient_id is an identifier. These descriptions answer different questions and are all necessary.

Categorical variables

A categorical variable places each observation into one of a defined set of groups. The values describe membership, not measured amounts.

Binary categorical variables

A binary variable has two categories. Examples include:

  • died within 30 days: yes or no;
  • blood culture positive: yes or no; and
  • allocated treatment group: intervention or control.

Binary variables are usually summarised using the number and percentage in each category. The denominator—the number of observations contributing to the percentage—must be stated when values are missing.

Unordered categorical variables

An unordered categorical variable has more than two categories without a natural ranking. This is also called a nominal variable.

In the scenario, smoking status may be recorded as:

  • never smoked;
  • former smoker; or
  • current smoker.

Hospital site is another unordered categorical variable. Site A is not greater or less than Site B.

Ordered categorical variables

An ordered categorical variable has categories with a meaningful sequence, but the distance between adjacent categories is not known to be equal. This is also called an ordinal variable.

The pneumonia severity grade may be:

  • mild;
  • moderate; or
  • severe.

Severe represents greater clinical severity than moderate, but the difference between mild and moderate is not necessarily the same as the difference between moderate and severe. Replacing the labels with 1, 2 and 3 does not turn the variable into a measured numerical quantity.

Numerical variables

A numerical variable records an amount for which arithmetic has clinical or scientific meaning. Differences, totals or ratios may be meaningful depending on the measurement.

Discrete numerical variables

A discrete variable takes separate countable values, commonly whole-number counts.

Examples from the scenario include:

  • respiratory rate recorded as breaths per minute;
  • number of chronic conditions; and
  • number of hospital admissions during the previous year.

A participant cannot have 2.6 chronic conditions. Counts may have many possible values, may be concentrated toward one end and may contain many zeros. Being numerical does not guarantee a bell-shaped pattern.

Continuous numerical variables

A continuous variable represents a measurement that can, in principle, take any value within a range. Examples include age, oxygen saturation, body temperature and C-reactive protein concentration.

In practice, instruments and data-entry systems record continuous measurements to finite precision. Oxygen saturation may be stored as a whole percentage and age may be recorded to one decimal place. Rounding changes the recorded values but does not automatically change the underlying clinical concept from a measurement into a category.

A useful distinction is therefore:

  • the underlying variable, such as exact age, which varies continuously with time; and
  • the recorded variable, such as age in completed years, which has only whole-number values in the dataset.

The intended scientific interpretation should guide classification and analysis.

Dates, times, text and derived variables

Dates and times require structured storage. 2026-05-12 09:40 should be stored as a date-time value rather than unstructured text. A date-time can be used to derive clinically meaningful numerical variables, such as time from admission to first antibiotic dose in minutes.

Free-text fields may be necessary for clinical notes or an “other, specify” response. They are not automatically ready for quantitative analysis. A reproducible coding process is needed before free text becomes a categorical or numerical variable.

Derived variables should be defined before analysis whenever possible. For example:

  • age can be derived from date of birth and the admission date;
  • time to antibiotic treatment can be derived from two date-time variables; and
  • body mass index can be derived from weight and height.

The original source variables should usually be retained so that the calculation can be checked.

Data structure

Simulated pneumonia-study variables

simulated data

Table 1. Variable roles and data types in the pneumonia study

VariableExample valueStatistical roleData type
patient_idP001IdentifierText identifier, not analysed
hospital_siteSite BDesign or grouping variableUnordered categorical
age_years68.4 yearsExplanatory variableNumerical measurement
smoking_statusFormer smokerExplanatory variableUnordered categorical
severity_gradeSevereExplanatory variableOrdered categorical
respiratory_rate31 breaths/minExplanatory variableDiscrete numerical count per minute
oxygen_saturation_pct88%Explanatory variableNumerical measurement
crp_mg_l176 mg/LExplanatory variableNumerical measurement
comorbidity_count3Explanatory variableNumerical count
admission_datetime2026-05-12 09:40Timing variableStructured date-time
death_30dYesOutcome variableBinary categorical

Note: CRP = C-reactive protein. Units form part of the variable definition.

Table 2. Four simulated participant records

patient_idage_yearsseverity_gradecrp_mg_ldeath_30d
P00168.4Severe176Yes
P00245.7Mild42No
P00379.1Severe231No
P00461.3Moderate98No

Note: Each row represents one participant, and each participant contributes one admission record to this example.

A data dictionary documents what each variable means, how it is coded, its unit, permitted values, missing-value rules and any derivation. Electronic data-capture systems can use these definitions to support consistent collection and validation [4]. Data management procedures should be planned before analysis rather than reconstructed after inconsistencies are discovered [5].

How data type guides description and analysis

Data type narrows the sensible choices for summaries and graphs, but it does not determine the final method by itself. The research objective, study design, distribution, repeated measurements and missing data also matter.

Table 3. Common descriptive approaches by data type

Data typeSuitable descriptive summaryCommon display
Binary categoricalNumber and percentage in each categoryBar chart or proportion plot
Unordered categoricalNumber and percentage in each categoryBar chart
Ordered categoricalNumber and percentage across ordered categoriesOrdered bar chart
Numerical countMean and standard deviation or median and interquartile range, as appropriateDot plot, histogram or box plot
Numerical measurementMean and standard deviation or median and interquartile range, as appropriateDot plot, histogram or box plot
Date-timeCalendar time or a derived duration with stated unitsTimeline or plot of elapsed time

Note: A distribution is the pattern and spread of observed values. The mean is the arithmetic average, the median is the middle ordered value, the standard deviation describes spread around the mean, and the interquartile range spans the middle 50% of values. Select a summary according to the clinical question and observed distribution, not solely from a formal test of whether the data follow a bell-shaped pattern.

The same clinical concept can be recorded in more than one form. Exact age in years is numerical, whereas age group is categorical. C-reactive protein concentration in mg/L is numerical, whereas “above the laboratory reference limit” is binary categorical. The original measurement usually contains more information than the grouped version.

Worked example

Recording and reporting variables

Variable definitions should be sufficiently precise for another researcher to understand what was collected. A name such as outcome is inadequate. A name such as death_30d is more informative but still requires a definition stating the event, time window, ascertainment source and coding.

The Results wording is illustrative. It describes the variable types appropriately but does not claim an association or causal effect.

Coding and data-quality safeguards

Good coding preserves the meaning of a variable.

Define categories before data collection

Categories should be mutually exclusive where possible and adequate for the study purpose. An “other, specify” field may be needed when a fixed list cannot anticipate every valid response.

Do not disguise missing data as a valid value

A missing C-reactive protein result should not be coded as 0, because zero may be interpreted as observed. Codes such as 999 are also risky unless documented and converted to recognised missing values before analysis.

“Unknown”, “not measured” and “not applicable” may differ and should not be silently combined with a genuine clinical category.

Record units consistently

A numerical value is incomplete without its unit. Mixing mg/L and mg/dL in one column can create serious errors even when every cell contains a valid number. The variable name, data dictionary and data-entry form should state the required unit.

Preserve the original measurement

Grouping a continuous measurement can be appropriate when a clinical threshold defined before examining outcomes is central to the question. The original measurement should usually be retained, with the grouped version stored as an additional derived variable.

Why unnecessary dichotomisation can weaken an analysis MMed extension

Dichotomisation means converting a numerical variable into two categories, such as classifying C-reactive protein as below or above a cut-off.

This conversion discards differences within each category. Two patients with concentrations of 51 and 250 mg/L may be treated as identical if both are above a 50 mg/L threshold. Unnecessary dichotomisation can reduce statistical efficiency—the precision obtained from the available data—hide relationships that do not follow a straight-line pattern and make results depend heavily on the selected cut-off [6].

A clinically established threshold may still be useful for treatment or communication. A sound dataset can retain both the original measurement and a category based on a threshold chosen before outcomes are examined. Cut-offs selected after examining the outcome require particular caution because they can exaggerate apparent associations.

Common mistakes

Knowledge check

Smoking status is stored as 0 = never, 1 = former and 2 = current. Is it numerical?

Answer and reasoning

No. Smoking status is an unordered categorical variable. The numbers are labels chosen for storage. Adding or averaging them would not produce a clinically meaningful quantity because the categories do not have equal numerical distances.

How should respiratory rate recorded as breaths per minute be classified?

Answer and reasoning

It is a discrete numerical variable because it is a count of breaths within a defined one-minute period. It should retain its unit, breaths per minute. A derived category such as tachypnoea may also be created using a definition chosen before analysis, but the original count should normally be retained.

A missing C-reactive protein result is entered as 0 mg/L. What is the problem?

Answer and reasoning

The code makes a missing observation appear to be a real measured value. This can distort summaries and analyses. The dataset should use an explicit missing-value representation and document why the result is absent when that distinction is relevant.

What is lost when exact age is replaced by age groups?

Answer and reasoning

Differences between people within the same age group are no longer represented, and people on opposite sides of a cut-off may appear artificially different. Age groups can support communication or a prespecified clinical decision, but retaining exact age preserves more information for analysis.

Can one variable be both an outcome and categorical?

Answer and reasoning

Yes. Variable role and data type are separate. In the pneumonia study, 30-day death is the outcome variable and is also binary categorical. An outcome could instead be numerical, such as length of hospital stay, depending on the research question.

Key take-home messages

References

  1. Altman DG. Practical statistics for medical research. London: Chapman and Hall; 1991.
  2. Kirkwood BR, Sterne JAC. Essential medical statistics. 2nd ed. Oxford: Blackwell Science; 2003.
  3. Bland M. An introduction to medical statistics. 4th ed. Oxford: Oxford University Press; 2015.
  4. Harris PA, Taylor R, Thielke R, Payne J, Gonzalez N, Conde JG. Research electronic data capture (REDCap)—a metadata-driven methodology and workflow process for providing translational research informatics support. J Biomed Inform. 2009;42(2):377–381. https://doi.org/10.1016/j.jbi.2008.08.010
  5. Krishnankutty B, Bellary S, Kumar NBR, Moodahadu LS. Data management in clinical research: an overview. Indian J Pharmacol. 2012;44(2):168–172. https://doi.org/10.4103/0253-7613.93842
  6. Royston P, Altman DG, Sauerbrei W. Dichotomizing continuous predictors in multiple regression: a bad idea. Stat Med. 2006;25(1):127–141. https://doi.org/10.1002/sim.2331

These notes support learning and research planning and do not replace statistical consultation for a specific study.

Report an error in this lecture