Statalist


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

Re: st: reshape world development indicators dataset


From   Svend Juul <[email protected]>
To   [email protected]
Subject   Re: st: reshape world development indicators dataset
Date   Wed, 2 Apr 2008 09:08:16 +0200


Marco wrote:

I need to reshape a World Development Indicators dataset. 
Currently, it is organized as follows.

country     var        year2000    year2001   year2002
Angola      GDP         100          102        104
Angola      Export       20           21         20
Algeria     GDP         200          202        204
Algeria     Export       10           11         10

country and var are string variables.

The dataset has 26500 rows and 43 columns (53 countries, 
37 years, 500 variables per country). I could reduce this 
if the size is a problem.

I would need the dataset to be organized as follows

country     year     GDP     Export
Angola      2000     100      20
Angola      2001     102      21
Angola      2002     104      20
Algeria     2000     200      10
Algeria     2001     202      11
Algeria     2002     204      10

This dataset would have 502 columns (country, year and 
500 variables), and 1961 rows (53 countries times 37 
years).

=======================================================

These commands do it:

     clear
     input str10 country str10 var year2000 year2001 year2002
     Angola      GDP         100          102        104
     Angola      Export       20           21         20
     Algeria     GDP         200          202        204
     Algeria     Export       10           11         10
     end

     reshape wide year* , i(country) j(var, string)
     renvars year* , map(substr("@",9,.) + substr("@",5,4))
     renvars _all, lower
     reshape long export gdp, i(country) j(year)

Hope this helps
Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone:  +45 8942 6090
Home:   +45 8693 7796
Email:  [email protected]
__________________________________________ 


*
*   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