*! version 1.0.0 17oct2020

sxpose2 -- Transponse of string (and numeric) variable dataset

Syntax

sxpose2, clear [options]

* clear reminder that untransposed data will be lost if not previously saved

destring tries to destring variables after the transponse has happened

firstnames apply specified format to all variables in transposed data

force allows to transponse numeric variables.

format(%fmt) apply specified format to all variables in transposed data

varlabel add variable _varlabel containing original variable label

varname add variable _varname containing original variable names

* clear is required.

Description

sxpose2 transposes the data, changing variables into observations and
observations into variables. In contrast to the implemented command xpose, it also
allows string variables to be transposed. It is build upon the well-received
user-written command sxpose and adds the possibility to keep variable names and/or
variable labels.

Options

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

destring specifies that destring, replace will be run on the new dataset
in an attempt to convert variables that are unambiguously numeric in content to numeric.
No force will be applied. See help on destring.

firstnames specifies that the first variable of the existing dataset is to be treated
the new variable names of the transposed dataset. Any values that are not legal variable names will be lost.

force is required when the dataset contains numeric variables. Numeric values will
be saved as strings using the format %12.0g by default. Other formats can be specified using the format() option.
Please be aware that you may lose precision using this option. The xpose command allows to
transpone a numeric dataset with higher precision.

format specifies a numeric format to use in coercing numeric values to string. See the force option.

varlname adds the new variable _varname to the transposed data containing
the original variable names.

varlabel adds the new variable _varlabel to the transposed data containing
the original variable labels.

Examples

Setup

. clear all

. input str1 id str1 var1 str1 var2

. "a" "d" "g"

. "b" "e" "h"

. "c" "f" "i"

. end

. label var var1 "VAR-1"

. label var var2 "VAR-2"

List the original data

. list

. sxpose2, clear firstnames varlabel varname

List the results

. list

Acknowledgements

Nicholas J. Cox who wrote sxpose. See:

Author

Stephan Huber

DrStephanHuber@yahoo.com

Also see

Online: help for xpose