Statalist


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

Re: st: stata question?


From   Svend Juul <[email protected]>
To   <[email protected]>
Subject   Re: st: stata question?
Date   Mon, 16 Feb 2009 11:28:33 +0100

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
 
Hope this helps
Svend
 
________________________________________________________ 
 
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Bartholins Allé 2
DK-8000 Aarhus C,  Denmark 
Phone, work:   +45 8942 6090 
Phone, home:   +45 8693 7796 
Fax:           +45 8613 1580 
E-mail:        [email protected] 
_________________________________________________________ 

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