*! version 3.0.0 21 Apr 2026

Title

timealloc -- Create diary-level time-allocation variables from episode data

Syntax

timealloc varlist, did(varlist) [shares(string)]

where varlist contains 1 to 6 numeric categorical diary fields.

did(varlist) variables that uniquely identify each diary; required

shares(string) custom proportions used to split episode duration across supplied variables; optional

Description

timealloc converts an episode-level diary dataset into a diary-level dataset with one row per diary.

For each category of the first variable in varlist, the command creates variables showing how much time the diarist spent in that category during the day. If only one diary field is supplied, timealloc also creates variables counting
how many episodes fall into each category.

This command is especially useful when researchers want a diary-level file summarising time spent in categories such as activities, locations, or co-presence states.

You may supply up to six diary fields. When more than one variable is supplied, the first is treated as the primary field, and the others are treated as secondary, tertiary, and so on. This makes it possible to allocate time across simultaneous activities rather than relying only on the primary activity.

By default, when more than one variable is supplied, episode duration is divided equally across all nonmissing supplied variables within the episode. Alternatively, the shares() option may be used to assign a custom split.

After creating the diary-level variables, timealloc reports whether the generated time-allocation variables sum to 1440 minutes. If they do not, this usually means that the diary field being summarised contains missing or unclassified values.

Required variables

start must be present in the data and must record the start minute of each episode.

end must be present in the data and must record the end minute of each episode.

Episode duration is calculated as end - start.

Arguments

varlist specifies one to six numeric categorical diary fields whose categories define the dimension over which time will be allocated. These might include activity variables, location variables, or co-presence variables. Value labels are strongly recommended, because they are used in the labels of the generated output variables when available.

did(varlist) specifies one or more variables that, taken together, uniquely identify a diary. These variables may be numeric or string.

Options

shares(string) specifies how episode duration should be split across the supplied variables when more than one variable appears in varlist.

In practice, users should provide a list of percentages, one for each supplied variable. The number of values in shares() must match the number of variables in varlist. Values must be between 0 and 100 and must sum to 100.

For example:

timealloc main sec, did(hldid persid id) shares(90 10)

assigns 90% of each episode's duration to the first variable and 10% to the second, after ignoring missing activity slots within the episode and rescaling among the activities that are actually present.

If only one variable is supplied, shares() is ignored.

What the command creates

Suppose the first variable in varlist is main4, and it contains categories 1 through 4.

Then timealloc creates:

main4_1 to main4_4 -- minutes per day spent in each category

If only one variable was supplied, it also creates:

main4_1_n to main4_4_n -- number of episodes in each category

When value labels are attached to the variable, they are used in the variable labels of the generated outputs.

How simultaneous activities are handled

When more than one variable is supplied, timealloc first redistributes each episode's duration across the nonmissing supplied variables.

By default, this split is equal. For example, if an episode has both a primary and a secondary activity, each receives half of the episode duration.

If shares() is used, the split follows the proportions provided by the user. If some later activity variables are missing in a particular episode, the specified shares are rescaled across the activities that are actually present in that episode.

Because episode counts become hard to interpret when one episode contributes time to several simultaneous activities, timealloc does not create count variables when more than one diary field is supplied.

Automatic correction of gapped activity fields

If multiple activity variables are supplied and an episode contains a missing earlier field but a nonmissing later field, timealloc shifts the valid later values left so that the first supplied activity field is nonmissing whenever possible.

For example, if the first activity variable is missing but the second contains a valid code, the second activity will be moved into the first position. When this happens, the command displays a note in the Results window.

This behavior is intended to make simultaneous-activity fields easier to use when they contain internal gaps.

Dataset after running the command

After running timealloc, the data are reduced to one row per diary.

The identifier variables specified in did() and the newly created diary-level summary variables are placed first in the dataset. Other variables originally present in the file are preserved, although episode-level variables are no longer meaningful once the data have been converted to diary level.

Examples

Example 1: Primary activity only

This example allocates time using only the primary activity field. Because only one variable is supplied, both minutes-per-day variables and episode-count variables are created.

. use MTUS_hef, clear

. m69tom4 main, gen(main4)

. timealloc main4, did(hldid persid id)

Example 2: Primary and secondary activities, equal split

This example uses both primary and secondary activities. Because no shares() option is specified, each episode's duration is divided equally across the nonmissing supplied activities.

. use MTUS_hef, clear

. m69tom4 main, gen(main4)

. m69tom4 sec, gen(sec4)

. timealloc main4 sec4, did(hldid persid id)

Example 3: Primary and secondary activities, custom split

This example gives greater weight to the primary activity than to the secondary one.

. use MTUS_hef, clear

. m69tom4 main, gen(main4)

. m69tom4 sec, gen(sec4)

. timealloc main4 sec4, did(hldid persid id) shares(90 10)

Remarks

1. Missing values and the 1440-minute check

If the generated minute variables do not sum to 1440, this usually means that the first supplied diary field contains missing or uncoded values. This is not necessarily an error, but users who want complete daily totals should recode those values before running timealloc.

2. Counts are only created with one diary field

Episode counts are created only when a single variable is supplied. This is intentional: once one episode is split across several simultaneous activities, the meaning of “number of episodes” becomes ambiguous.

3. Output variable names are based on the first supplied variable

Even when several diary fields are supplied, the created output variables are named using the first variable in varlist. This first variable acts as the common activity field after simultaneous activities have been redistributed.

4. Input data should be structurally sound

timealloc assumes that start and end correctly describe episode timing. If the input file may contain gaps, overlaps, or other episode-structure problems, it is good practice to check and fix the
episode file before using timealloc.

Stored results

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

Author

Juana Lamote de Grignon-Pérez

Centre for Time Use Research (CTUR)

Also see

Related commands in the same toolkit may include commands used to check, reshape, or repair episode-level diary files before diary-level summaries are created.