Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Transforming data - horizontal to vertical


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Transforming data - horizontal to vertical
Date   Wed, 11 May 2011 11:11:04 +0200

On Wed, May 11, 2011 at 10:43 AM, lreine ycenna wrote:
> I need to re-convert my data into the stata format (vertical). What
> command do I use? <snip>

You can get where you want with two calls to -reshape-, like in the
example below (in which I added a second variable x2).

*-------------------- begin example ------------------------
clear all
input str2 var year USA AUS
x1 1997  0.1   0.1
x1 1998  0.2   0.5
x1 1999  0.1   0.3
x1 2000  0.3   0.3
x2 1997  1     1
x2 1998  2     5
x2 1999  1     3
x2 2000  3     3
end

// this will put the countries underneath one another
rename USA c1
rename AUS c2
reshape long c, i(var year) j(country)
label define country 1 "USA" 2 "Australia"
label value country country
list

// this will put the variables side by side
reshape wide c , i(country year) j(var) string
rename cx1 x1
rename cx2 x2
list
*------------------------ end example ------------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index