📄 stack.hlp
字号:
{smcl}
{* 20jan2005}{...}
{cmd:help stack}{right:dialog: {bf:{dialog stack}}}
{hline}
{title:Title}
{p2colset 5 18 20 2}{...}
{p2col :{hi:[D] stack} {hline 2}}Stack data{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 14 2}
{cmd:stack}
{varlist}
{ifin}
{cmd:,}
{c -(}{cmdab:i:nto(}{it:newvars}{cmd:)}|{opt g:roup(#)}{c )-}
[{it:options}]
{synoptset 17 tabbed}{...}
{synopthdr}
{synoptline}
{syntab :Main}
{p2coldent :* {opth i:nto(newvar:newvars)}}identify names
of new variables to be created{p_end}
{p2coldent :* {opt g:roup(#)}}stack {it:#} groups of variables in
{varlist}{p_end}
{synopt :{opt clear}}clear dataset from memory{p_end}
{synopt :{opt wi:de}}keep variables in {it:varlist} that are not specified in
{it:newvars}{p_end}
{synoptline}
{p 4 6 2}
* Either {opt into(newvars)} or {opt group(#)} is required.{p_end}
{title:Description}
{pstd}
{opt stack} stacks variables in {varlist} vertically,
resulting in a dataset with variables {it:{help newvar:newvars}} and
{helpb _N}*(Nv/Nn) observations, where Nv is the number of variables in
{it:varlist} and Nn is the number in {it:newvars}.
{opt stack} creates the new variable {cmd:_stack} identifying the groups.
{title:Options}
{dlgtab:Main}
{phang}
{opth "into(newvar:newvars)"}
specifies the names of the new variables to be created.
{opt into()} may be specified using variable ranges
(e.g., {cmd:into(v1-v3)}). Either {opt into()} or {opt group()},
but not both, must be specified.
{phang}
{opt group(#)} specifies the number of groups of variables in {varlist} to be
stacked. The created variables will be named according to the first group in
{it:varlist}. Either {opt into()} or {opt group()},
but not both, must be specified.
{phang}
{opt clear} indicates that it is okay to clear the dataset in memory.
If you do not specify this option, you will be asked to confirm your intentions.
{phang}
{opt wide} includes any of the original variables in {varlist} that
are not specified in {it:{help newvar:newvars}} in the resulting data.
{title:Remarks}
{pstd}
This command is best understood by examples. Consider
{phang2}{cmd:. stack a b c d e f, into(g h)}
{pstd}
This would create a new dataset containing
g{col 12}h{col 24}{cmd:_stack}
{hline 25}
a{col 12}b{col 26}1{col 34}(_N observations)
c{col 12}d{col 26}2{col 34}(_N observations)
e{col 12}f{col 26}3{col 34}(_N observations)
{pstd}
The resulting dataset would have 3*_N observations. The first _N
observations would have all the data from variables a and b, the second _N
observation all the data from c and d, and the third _N observations all the
data from e and f.
{pstd}
{opt stack} also creates a new variable, {cmd:_stack}, identifying the
groups.
{pstd}
As another example,
{phang2}{cmd:. stack a b c d e f, into(g h i)}
{pstd}
would create a new dataset containing
g{col 12}h{col 19}i{col 24}{cmd:_stack}
{hline 25}
a{col 12}b{col 19}c{col 26}1{col 34}(_N observations)
d{col 12}e{col 19}f{col 26}2{col 34}(_N observations)
{pstd}
The number of variables specified by {opt into()} determine the number of
groups formed. {opt into()} may be specified with variable ranges, such as
{phang2}{cmd:. stack a b c d e f, into(v1-v3)}
{pstd}
as, of course, may the {varlist}
{phang2}{cmd:. stack a-f, into(v1-v3)}
{pstd}
The new variables formed may have the existing variables' names;
{phang2}{cmd:. stack a b c d e f, into(a b)}{p_end}
and
{phang2}{cmd:. stack a b c d e f, into(a b c)}
make perfect sense.
{pstd}
When you want the new variables to have the same names as the variables in
the first group, rather than specifying {opt into()}, you may specify
{opt group()}. Equivalent to the above are
{phang2}{cmd:. stack a b c d e f, group(2)}{p_end}
and
{phang2}{cmd:. stack a b c d e f, group(3)}
{pstd}
For instance, the latter command creates
a{col 12}b{col 24}{hi:_stack}
{hline 25}
a{col 12}b{col 26}1{col 34}(_N observations)
c{col 12}d{col 26}2{col 34}(_N observations)
e{col 12}f{col 26}3{col 34}(_N observations)
{title:Examples}
{cmd:. list}
a b c d
1. {res}1 2 3 4{txt}
2. {res}5 6 7 8{txt}
{cmd:. stack a b c d, into(e f) clear}
{cmd:. list}
e f _stack
1. {res}1 2 1{txt}
2. {res}5 6 1{txt}
3. {res}3 4 2{txt}
4. {res}7 8 2{txt}
{pstd}
The new variable {cmd:e} is formed by stacking {cmd:a} and {cmd:c},
while the new variable {cmd:f} is formed by stacking {cmd:b} and {cmd:d}.
{cmd:_stack} is automatically created and set equal to 1 for the first
({cmd:a},{cmd:b}) group and 2 for the second ({cmd:c},{cmd:d}) group.
{title:Also see}
{psee}
Manual: {bf:[D] stack}
{psee}
Online:
{helpb contract},
{helpb reshape},
{helpb xpose}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -