reshape converts data from wide to long form and vice versa. Think of the data as a collection of
observations x_ij. One such collection might be
(wide form)
-i- ------- x_ij --------
id sex inc80 inc81 inc82
-------------------------------
1 0 5000 5500 6000
2 1 2000 2200 3300
3 0 3000 2000 1000
(long form)
-i- -j- -x_ij-
id year sex inc
-----------------------
1 80 0 5000
1 81 0 5500
1 82 0 6000
2 80 1 2000
2 81 1 2200
2 82 1 3300
3 80 0 3000
3 81 0 2000
3 82 0 1000
reshape converts data from one form to the other:
. reshape long inc, i(id) j(year) (goes from top-form to bottom)
. reshape wide inc, i(id) j(year) (goes from bottom-form to top)
See [R] reshape for a detailed discussion and examples for both the basic and advanced syntax.
Options
i(varlist) specifies the variable(s) whose unique values denote a logical observation.
j(varname [values]) specifies the variable whose unique values denote a subobservation. values list the
unique values to be used from varname and typically is not explicitly stated since reshape will determine
them automatically from the data.
string specifies that the j() may contain string values.
atwl(chars) specifies that chars should be substituted for the @ character when converting the data to the
long form.
Examples
. reshape long inc ue, i(id) j(year) converts from wide to long
. reshape wide converts back to wide
. reshape ..., i(id) one i() variable
. reshape ..., i(hid pid) two i() variables
. reshape long inc, i(id) j(year 80-82 85) specifying j() values
. reshape long inc, i(id) j(sex) string allow string var. in j()
|