📄 reshape.hlp
字号:
{smcl}
{* 14mar2005}{...}
{cmd:help reshape} {right:dialog: {bf:{dialog reshape}}}
{hline}
{title:Title}
{p2colset 5 20 22 2}{...}
{p2col :{hi:[D] reshape} {hline 2}}Convert data from wide to long and vice versa{p_end}
{p2colreset}{...}
{title:Syntax}
{phang}
Basic syntax
{p 8 17 2}
{cmd:reshape long} {it:stubnames}{cmd:,} {opt i(varlist)}
[{it:{help reshape##options:options}}]
{p 8 17 2}
{cmd:reshape wide} {it:stubnames}{cmd:,} {opt i(varlist)}
[{it:{help reshape##options:options}}]
{p 8 17 2}
{cmd:reshape long}
{p 8 17 2}
{cmd:reshape wide}
{p 8 17 2}
{cmd:reshape error}
{phang}
Advanced syntax
{p 8 17 2}
{cmd:reshape i} {varlist}
{p 8 17 2}
{cmd:reshape j} {varname} [{it:values}] [{it:,} {opt s:tring}]
{p 8 17 2}
{cmd:reshape xij} {it:fvarnames} [{cmd:,} {opt at:wl(chars)}]
{p 8 17 2}
{cmd:reshape xi} [{varlist}]
{p 8 17 2}
{cmd:reshape} [{opt q:uery}]
{p 8 17 2}
{cmd:reshape clear}
{synoptset 23 tabbed}{...}
{marker options}{...}
{synopthdr}
{synoptline}
{syntab :Main}
{p2coldent:* {opth i(varlist)}}use {it:varlist} as the ID variables{p_end}
{synopt :{opt j}{cmd:(}{varname} [{it:values}]{cmd:)}}use {it:stubnames} for
X_ij variables; optionally, and on {bf:Advanced} tab, use {it:values} from
{it:varname} to identify subobservations{p_end}
{syntab :Advanced}
{synopt :{opt s:tring}}allow the subobservation identifier to include strings{p_end}
{synopt :{opt at:wl(chars)}}substitute {it:chars} for the {cmd:@} character when converting to long form{p_end}
{synoptline}
{p2colreset}{...}
{p 4 6 2}* {opt i(varlist)} is required.
{phang}
where {it:values} is {space 5} {it:#}[-{it:#}] [{it:#}[-{it:#}]{cmd:...}]
{phang}
and {it:fvarnames} are either variable names, variable names with {cmd:@}
characters, or a mix of the two. The {cmd:@} character denotes where the
{it:#} {cmd:j} suffix appears.
{title:Description}
{pstd}
{cmd:reshape} converts data from wide to long form and vice versa.
{title:Options}
{dlgtab:Main}
{phang}
{opt i(varlist)} specifies the variables whose unique values denote a
logical observation. {opt i()} is required.
{phang}
{cmd:j(}{varname} [{it:values}]{cmd:)} specifies the variable whose
unique values denote a subobservation. {it:values} lists the unique values to
be used from {it:varname}, which typically are not explicitly stated since
{cmd:reshape} will determine them automatically from the data.
{dlgtab:Advanced}
{phang}
{opt string} specifies that the {opt j()} may contain string values.
{phang}
{opt atwl(chars)} specifies that {it:chars} should be substituted for the
{cmd:@} character when converting the data to the long form.
{title:Remarks}
{pstd}
Before using {cmd:reshape}, you need to determine whether the data are in long
or short form. You also must determine the logical observation (i) and the
subobservation (j) by which to organize the data. Suppose that you had the
following data, which could be organized in wide or long form as follows:
{center: (wide form) }
{center:{cmd:i}{space 8}....... x_ij ........}
{center:{cmd:id sex inc80 inc81 inc82}}
{center:{hline 31}}
{center: 1 0 5000 5500 6000}
{center: 2 1 2000 2200 3300}
{center: 3 0 3000 2000 1000}
{center: (long form) }
{center:{cmd:i}{space 5}{cmd:j}{space 11}x_ij}
{center:{cmd:id year sex inc }}
{center:{hline 23}}
{center: 1 80 0 5000 }
{center: 1 81 0 5500 }
{center: 1 82 0 6000 }
{center: 2 80 1 2000 }
{center: 2 81 1 2200 }
{center: 2 82 1 3300 }
{center: 3 80 0 3000 }
{center: 3 81 0 2000 }
{center: 3 82 0 1000 }
{pstd}
Given this data, you could use {cmd:reshape} to convert from one form to the
other:
{p 8 43 2}{cmd:. reshape long inc, i(id) j(year)}{space 2}(goes from top-form to
bottom){p_end}
{p 8 43 2}{cmd:. reshape wide inc, i(id) j(year)}{space 2}(goes from bottom-form
to top)
{pstd}
See {bf:[D] reshape} for a detailed discussion and examples for both the
basic and advanced syntax.
{title:Examples}
{cmd:. reshape long inc ue, i(id) j(year)}{right:converts from wide to long }
{cmd:. reshape wide}{right:converts back to wide }
{cmd:. reshape} {it:...}, {cmd:i(id)}{right:one {cmd:i()} variable }
{cmd:. reshape} {it:...}, {cmd:i(hid pid)}{right:two {cmd:i()} variables }
{cmd:. reshape long inc, i(id) j(year 80-82 85)}{right:specifying {cmd:j()} values }
{cmd:. reshape long inc, i(id) j(sex) string}{right:allow string var. in {cmd:j()} }
{title:Also see}
{psee}
Manual: {bf:[D] reshape}
{psee}
Online: {helpb char}, {helpb save}, {helpb stack}, {helpb xpose}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -