Stata 15 help for xpose

[D] xpose -- Interchange observations and variables

Syntax

xpose, clear [options]

options Description ------------------------------------------------------------------------- * clear reminder that untransposed data will be lost if not previously saved format use largest numeric display format from untransposed data format(%fmt) apply specified format to all variables in transposed data varname add variable _varname containing original variable names promote use the most compact data type that preserves numeric accuracy ------------------------------------------------------------------------- * clear is required.

Menu

Data > Create or change data > Other variable-transformation commands > Interchange observations and variables

Description

xpose transposes the data, changing variables into observations and observations into variables. All new variables -- that is, those created by the transposition -- are made the default storage type. Thus any original variables that were strings will result in observations containing missing values. (If you transpose the data twice, you will lose the contents of string variables.)

Options

clear is required and is supposed to remind you that the untransposed data will be lost (unless you have saved the data previously).

format specifies that the largest numeric display format from your untransposed data be applied to the transposed data.

format(%fmt) specifies that the specified numeric display format be applied to all variables in the transposed data.

varname adds the new variable _varname to the transposed data containing the original variable names. Also, with or without the varname option, if the variable _varname exists in the dataset before transposition, those names will be used to name the variables after transposition. Thus transposing the data twice will (almost) yield the original dataset.

promote specifies that the transposed data use the most compact numeric data type that preserves the original data accuracy.

If your data contain any variables of type double, all variables in the transposed data will be of type double.

If variables of type float are present, but there are no variables of type double or long, the transposed variables will be of type float. If variables of type long are present, but there are no variables of type double or float, the transposed variables will be of type long.

Examples

--------------------------------------------------------------------------- Setup . webuse xposexmpl

List the original data . list

Interchange observations and variables, and store original variable names in _varname . xpose, clear varname

List the results . list

Restore original data . xpose, clear

A list shows that the data have been restored . list

Interchange observations and variables, store original variable names in _varname, and use %6.2f format on numeric variables . xpose, clear varname format(%6.2f)

List the results . list

--------------------------------------------------------------------------- Setup . webuse xposexmpl, clear

Describe the original data . describe

Interchange observations and variables, store original variable names in _varname, and apply largest numeric display format from untransformed data to variables in transposed data . xpose, clear varname format

Describe the resulting data . describe ---------------------------------------------------------------------------


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index