. use "C:\Documents and Settings\ssbing\桌面\qq.dta"
. list
+------------------------+
| id x1 x2 y1 y2 |
|--------------------------|
1. | a 10 14 0 4 |
2. | b 11 15 1 5 |
3. | c 12 16 2 6 |
4. | d 13 17 3 7 |
+-------------------------+
. reshape long x y,i(id)
(note: j = 1 2)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 4 -> 8
Number of variables 5 -> 4
j variable (2 values) -> _j
xij variables:
x1 x2 -> x
y1 y2 -> y
-----------------------------------------------------------------------------
. list
+------------------+
| id _j x y |
|--------------------|
1. | a 1 10 0 |
2. | a 2 14 4 |
3. | b 1 11 1 |
4. | b 2 15 5 |
5. | c 1 12 2 |
|--------------------|
6. | c 2 16 6 |
7. | d 1 13 3 |
8. | d 2 17 7 |
+-------------------+
. reshape wide x y,i(id)
(note: j = 1 2)
Data long -> wide
-----------------------------------------------------------------------------
Number of obs. 8 -> 4
Number of variables 4 -> 5
j variable (2 values) _j -> (dropped)
xij variables:
x -> x1 x2
y -> y1 y2
-----------------------------------------------------------------------------
. list
+-------------------------+
| id x1 y1 x2 y2 |
|---------------------------|
1. | a 10 0 14 4 |
2. | b 11 1 15 5 |
3. | c 12 2 16 6 |
4. | d 13 3 17 7 |
+-------------------------+