Statalist


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

Re: st: reshape world development indicators dataset


From   Daniel Wilde <dgw24@bath.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: reshape world development indicators dataset
Date   Wed, 02 Apr 2008 10:16:28 +0100

Hi,

I found the following document very useful for using WDI data in stata:

<http://spot.colorado.edu/~moonhawk/technical/C1912567120/E220703361/Media/reshape.pdf>

Thanks

Dan

--On 02 April 2008 09:41 +0100 BW Wheeler <ben.wheeler@bristol.ac.uk> wrote:

--On 01 April 2008 22:24 -0700 marco stampini <marco_stampini@yahoo.com>
wrote:

Hello.
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).

I tried the usual reshape commands but had no success. I am sure I am
missing something. Your help would be most appreciated. Thanks in
advance. Marco


Marco,

Here's how I'd do it with two passes of -reshape-. There may be more
elegant ways. The confusion may be because on reshaping to long, you end
up with your data in a variable called _year_?

--------------------
reshape long year, i( country var) j(y)
rename year n
rename y year
reshape wide n, i( country year) j( var) str
--------------------

You end up with an 'n' prefix for the variables, but it should do the job?
Cheers
Ben



----------------------
Ben Wheeler
Research Fellow, University of Bristol
Department of Social Medicine
Department of Exercise, Nutrition & Health Sciences
& South West Public Health Observatory
e: ben.wheeler@bristol.ac.uk
*
*   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/



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index