*! version 3.0.0 21 Apr 2026

Title

epigenx -- Redefine an existing episode file using different episode boundaries

Syntax

epigenx varlist, did(varlist) [dst(#) nolabel]

where varlist contains the variables that should define the new episodes.

did(varlist) variable(s) that uniquely identify each diary; required

dst(#) diary start hour on a 24-hour clock; required unless nolabel is used

nolabel do not create clock-time labels or clockst

Description

epigenx takes a dataset that is already in episode format and creates a new episode file using different episode boundaries.

A new episode is created whenever any variable listed in varlist changes value.

This is useful when an existing episode file is defined using many dimensions, but your research question focuses on only one or a few of them.

For example:

- redefine episodes using only location to study mobility
- redefine episodes using only Enjoy to study mood changes across the day
- redefine episodes using only activity to simplify a complex file
- redefine episodes using activity location to retain both dimensions

In short:

epigen = calendar file to episode file
epigenx = episode file to a different episode file

Required variables

start must exist and contain the start minute of each episode.

end must exist and contain the end minute of each episode.

The file should already contain one row per episode.

Arguments

varlist specifies the variables that define the new episodes. Consecutive existing episodes are merged whenever all supplied variables remain unchanged.

Variables in varlist may be numeric or string.

The current version allows up to 20 variables in varlist.

did(varlist) specifies one or more variables that jointly identify each diary uniquely. Variables may be numeric or string.

Options

dst(#) specifies the diary start hour using an integer from 0 to 23.

Examples:

dst(0) = diary begins at midnight
dst(4) = diary begins at 04:00
dst(18) = diary begins at 18:00

This option is used to create readable clock labels for start and end, and to generate clockst.

dst() is required unless nolabel is specified.

nolabel suppresses creation of clock-time labels and suppresses clockst.

What the command creates

epigenx returns a new episode file with one row per newly defined episode.

It creates or recreates the following variables:

Output

epnum episode number within diary

start start minute of episode

end end minute of episode

time episode duration in minutes (end-start)

clockst clock-time start variable; omitted with nolabel

The variables listed in varlist are retained as the defining diary fields of the new file.

How the command works

Within each diary, epigenx compares consecutive existing episodes.

If all variables in varlist remain unchanged, adjacent episodes are merged into one longer episode.

If any supplied variable changes, a new episode begins.

This means the resulting file often contains fewer episodes than the starting file, especially when simplifying a richly coded sequence file.

Checks and warnings

epigenx checks that:

- start exists
- end exists
- the dataset appears to be in episode format
- identifier variables are present

If observations contain missing values in any variable listed in did(), those observations may be dropped after warning messages.

Dataset after running the command

The output remains an episode-level file, but with newly defined episodes.

Variables listed in did(), timing variables, and the new episode number appear first in the dataset.

Examples

Example 1: Redefine episodes using enjoyment only

Suppose the original file contains many short episodes, but the goal is to analyse changes in enjoyment across the day.

. use UK2014, clear

. gen start = tid*10 - 10

. gen end = start + eptime

. epicheck, did(serial pnum daynum)

. epigenx Enjoy, did(serial pnum daynum) dst(4)

Adjacent episodes with the same enjoyment score are merged.

Example 2: Redefine episodes using location

. epigenx where, did(pid day) dst(4)

Useful for analysing movement between places during the day.

Example 3: Redefine episodes using activity and location

. epigenx activity where, did(pid day) dst(4)

A new episode begins when either activity or location changes.

Example 4: Faster numeric-only output

. epigenx Enjoy, did(serial pnum daynum) nolabel

Use nolabel when you only need numeric times.

Remarks

1. Use when the file is already episodic

If your starting file is in calendar format (one row per slot), use epigen instead.

2. Simplification often reduces file size

If the original file uses many diary dimensions, redefining episodes with fewer variables often greatly reduces the number of rows.

3. Choose variables based on the research question

Use only the dimensions relevant to your analysis. For example, mood research may only need enjoyment, while mobility research may only need location.

4. Consecutive identical episodes are merged

If the same category reappears later after interruption, it becomes a new episode. Only adjacent episodes with identical values are merged.

5. dst() affects labels, not episode boundaries

Episode boundaries come from start and end. The dst() option is used for clock labels and clockst.

Stored results

epigenx does not store results in r() or e(). Results are returned through the transformed dataset.

Author

Juana Lamote de Grignon-Pérez

Centre for Time Use Research (CTUR)

Also see

epigen to convert calendar files into episode files.

timealloc for diary-level summaries from episode files.