Statalist


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

RE: st: stata question?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: stata question?
Date   Mon, 16 Feb 2009 10:50:29 -0000

I agree with Svend and others that this calls for -reshape-. Note that
no renaming is needed. 

reshape long Country, i(Indice Year) string 

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

Svend Juul

Arina wrote:
 
... I would like to stack some variables in my dataset 
but at the same time keep the rest of my variables - 
I am trying to code a loop for that but I can't seem 
to get it right. 
 
I.e., currently, my dataset currently looks like the 
following (I have about 100 indices for 15 years and 
200 countries): 
 
Indice    Year   CountryA     CountryB   CountryC 
1         1995    .2          .a         .1 
1         1996    .36        .12        .45 
2         1997    .15        .26        .45 
2         1999    .22        .33        .11 
3         1995    .a          .22        .33 
 
My question is how could I stack my country variables 
under one column named "Country"  by indice and year, 
and also have another column that would contain my values? 
so I would have the following: 
 
Indice Year  Country    Values 
1      1995  countryA      .2 
'      1995  countryB      .a       
'        '   countryC      .1 
'      1996  countryA 
'            countryB 
            countryC 
2      1997  countryA      .15 
'      1997  countryB      .26 
' 
3      1995  countryA      .a 
      1995  countryB      .22 
      1995  countryC      .33 
 
====================================================
 
This is a -reshape- problem. Rename your CountryX
variables to Country1, Country2, etc. and:
 
     reshape long Country , i(Indice Year) j(ncountry)
     rename Country Values
     rename ncountry Country
 

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