Statalist


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

RE: st: stata question?


From   Arina Viseth <[email protected]>
To   [email protected]
Subject   RE: st: stata question?
Date   Mon, 16 Feb 2009 07:19:33 -0500 (EST)

Dear statalist,

Thank you all very much for your answers. I understand that in order to use reshape, I would need to have the names in each group to all begin with the same stubname. However, my countries' names are all different: they go alphabetically from afghanistan, albania, algeria...etc to zimbabwe. I could change the name of each country and enter country1 for afghanistan country2 for albania..etc, but instead of doing it manually for 210 countries, is there another way to reshape my data the way mentioned below?

many thanks again for your help,
Arina 


---- Original message ----
>Date: Mon, 16 Feb 2009 10:50:29 -0000
>From: [email protected] (on behalf of "Nick Cox" <[email protected]>)
>Subject: RE: st: stata question?  
>To: <[email protected]>
>
>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 
>[email protected] 
>
>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/
*
*   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