Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# st: RE: RE: how to transform variables

 From "Qian Yu" To Subject st: RE: RE: how to transform variables Date Tue, 15 Nov 2011 13:39:20 +0100

```Hi, nick

Best
Qian

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 15 November 2011 13:14
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: RE: how to transform variables

input var1	var2
4	8
54	89
87	28
39	75
99	96
119	100
end
gen group1 = var1[1]
gen group2 = var2[1]
drop in 1
gen id = _n
reshape long var group , i(id)
sort group id

. l

+-----------------------+
| id   _j   var   group |
|-----------------------|
1. |  1    1    54       4 |
2. |  2    1    87       4 |
3. |  3    1    39       4 |
4. |  4    1    99       4 |
5. |  5    1   119       4 |
|-----------------------|
6. |  1    2    89       8 |
7. |  2    2    28       8 |
8. |  3    2    75       8 |
9. |  4    2    96       8 |
10. |  5    2   100       8 |
+-----------------------+

Nick
n.j.cox@durham.ac.uk

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of econqian
Sent: 15 November 2011 11:38
To: statalist@hsphsun2.harvard.edu
Subject: st: how to transform variables

Hi, all
How to transform the original format of two variables to the new
format of two variables?
Original format
Var1	Var2
4	8
54	89
87	28
39	75
99	96
119	100

New format
Va1	Var2
54	4
87	4
39	4
99	4
119	4
89	8
28	8
75	8
96	8
100	8

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```