Stata 11 help for separate

help separate dialog: separate -------------------------------------------------------------------------------

Title

[D] separate -- Create separate variables

Syntax

separate varname [if] [in] , by(byvar|exp) [options]

options description ------------------------------------------------------------------------- Main * by(byvar) categorize observations into groups defined by byvar * by(exp) categorize observations into two groups defined by exp

Options generate(stubname) name new variables by suffixing values to stubname; default is to use varname as prefix sequential use as name suffix categories numbered sequentially from 1 missing create variables for the missing values shortlabel create shorter variable labels ------------------------------------------------------------------------- * Either by(byvar) or by(exp) must be specified.

Menu

Data > Create or change data > Other variable-transformation commands > Create separate variables

Description

separate creates new variables containing values from varname.

Options

+------+ ----+ Main +-------------------------------------------------------------

by(byvar|exp) specifies one variable defining the categories or a logical expression that categorizes the observations into two groups.

If by(byvar) is specified, byvar may be a numeric or string variable taking on any values.

If by(exp) is specified, the expression must evaluate to true (1), false (0), or missing.

by() is required.

+---------+ ----+ Options +----------------------------------------------------------

generate(stubname) specifies how the new variables are to be named. If generate() is not specified, separate uses the name of the original variable, shortening it if necessary. If generate() is specified, separate uses stubname. If any of the resulting names is too long when the values are suffixed, it is not shortened and an error message is issued.

sequential specifies that categories be numbered sequentially from 1. By default, separate uses the actual values recorded in the original variable, if possible, and sequential numbers otherwise. separate can use the original values if they are all nonnegative integers smaller than 10,000.

missing also creates a variable for the category missing if missing occurs (byvar takes on the value missing or exp evaluates to missing). The resulting variable is named in the usual manner but with an appended underscore; e.g., bp_. By default, separate creates no such variable. The contents of other variables are unaffected by whether missing is specified.

shortlabel creates a variable label that is shorter than the default. By default, when separate generates the new variable labels, it includes the name of the variable being separated. shortlabel specifies that the variable name be omitted from the new variable labels.

Examples

--------------------------------------------------------------------------- Setup . sysuse auto

Create variable mpg0 containing values of mpg when foreign is 0 (Domestic) and create variable mpg1 containing values of mpg when foreign is 1 (Foreign) . separate mpg, by(foreign)

Plot quantiles of mpg0 against the quantiles of mpg1 . qqplot mpg0 mpg1

--------------------------------------------------------------------------- Setup . sysuse auto, clear

Create variable mpg0 containing values of mpg when price is not greater than 6000 and create variable mpg1 containing values of mpg when price is greater than 6000 . separate mpg, by(price>6000)

--------------------------------------------------------------------------- Setup . sysuse auto, clear

Same as above, but call variables mpgpr0 and mpgpr1 . separate mpg, by(price>6000) gen(mpgpr)

Plot quantiles of mpgpr0 against the quantiles of mpgpr1 . qqplot mpgpr0 mpgpr1 ---------------------------------------------------------------------------

Saved results

separate saves the following in r():

Macros r(varlist) names of the newly created variables

Also see

Manual: [D] separate

Help: [R] tabulate oneway, [R] tabulate twoway, [R] tabulate, summarize()


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