Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Reshaping data question


From   Keith Dear <[email protected]>
To   [email protected]
Subject   Re: st: Reshaping data question
Date   Tue, 08 Apr 2008 13:16:51 +1000

Glenn,
Well if you are then so am I (missing something obvious), but at least this works:

encode DATA_SERIES, gen(ds) // GDP=1 etc in alphabetical order
drop DATA_SERIES
reshape wide YR*, i(COUNTRY) j(ds)
forval y=1960/1962 {
rename YR`y'1 GDP`y'
rename YR`y'2 POP`y'
}
reshape long GDP POP, i(COUNTRY) j(YEAR)

Let's hope others do better!
Keith


At 12:27 PM 8/04/2008, you wrote:



I have data in a layout that is new to me and I'm stuck on how to
reshape it to what I need. Worse, I feel like I'm missing something
obvious. Any help would be much appreciated.

The data is in this layout (with fictional data)

COUNTRY DATA_SERIES YR1960 YR1961 YR1962
Argentina GDP 5 7 9
Argentina Population 10 8 5
Brazil GDP 1 9 10
Brazil Population 5 35 12

I would like to get it into this format:

COUNTRY YEAR GDP POPULATION
Argentina 1960 5 10
Argentina 1961 7 8
...Brazil 1960 1 5
Brazil 1961 9 35
etc.

It's the "DATA_SERIES" variable in the original data that is really
throwing me. I'm fairly comfortable with plain vanilla "reshape".
Thank you in advance for any help.

Glenn Hoetker
Glenn Hoetker
Associate Professor (Business, Law, Institute for Genomic Biology)
Resident Associate, Center for Advanced Study, Science and Technology
in the Pacific Century (STIP) initiative
Faculty Fellow, Academy for Entrepreneurial Leadership
University of Illinois
217-265-4081
[email protected]
Personal website: www.business.uiuc.edu/ghoetker
Science & Technology in the Pacific Century initiative website: www.business.uiuc.edu/stip

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

Dr Keith B.G. Dear
Senior Fellow in Biostatistics
National Centre for Epidemiology and Population Health
Australian National University
Canberra, ACT 0200, Australia
Tel: 02 612 54865, Fax: 02 612 50740
http://nceph.anu.edu.au/Staff_Students/staff_pages/dear.php
CRICOS provider #00120C

http://canberragliding.org/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index