*! version 1.0.0 20jan2026
help reshapelabel

Title

reshapelabel — Reshape long to wide using a string j-variable and
apply j-variable values as column labels

Syntax

reshapelabel,
metric(varname)
jvar(varname)
ivar(varlist)

Description

reshapelabel reshapes data from long to wide when the j-variable
is a string (including strings with spaces) and applies the string values
of the j-variable as variable labels on the reshaped wide variables.

This command is a safe wrapper around reshape wide that:

• accepts a string j-variable

• encodes the j-variable internally

• reshapes wide using numeric codes

• applies the original string values as variable labels

• verifies that the data are uniquely indexed prior to reshaping

Options

Options

metric(varname)
specifies the variable to be reshaped wide.

jvar(varname)
specifies the string variable whose distinct values define the wide columns.
This variable may contain spaces.

ivar(varlist)
specifies the variables that uniquely identify observations in long form.

Remarks

The command requires that the combination of ivar() and jvar()
uniquely identifies the dataset. If this condition is not met, the command
exits with error code 459 and displays a custom error message.

Internally, the command sorts by the j-variable before encoding to ensure
that the numeric codes assigned to j-variable values are stable and
independent of observation order.

After reshaping, the resulting wide variables are labeled using the original
string values of the j-variable.

Examples

Basic usage:

. input str1 firm str10 month sales
. "A" "Jan 2024" 10
. "A" "Feb 2024" 12
. "B" "Jan 2024" 8
. "B" "Feb 2024" 9
. end

. reshapelabel, metric(sales) jvar(month) ivar(firm)

This produces variables sales1, sales2, etc., labeled
"Jan 2024", "Feb 2024", and so on.

Returned results

None.

Errors

459 — The i-variable(s) do not uniquely index the dataset.

Author

Written by Arthi Thiruppathi.

reshape