Statalist


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

st: AW: stack question?


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: stack question?
Date   Sun, 15 Feb 2009 22:23:57 +0100

<> 



*************
help reshape
*************



HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Arina Viseth
Gesendet: Sonntag, 15. Februar 2009 22:15
An: [email protected]
Betreff: st: stack question?

Dear Statalist,

Thank you very much for all of your suggestions on my encode question, I
really appreciated your kind help - my variables have been back into
numerical thanks to you. 

I have another question and I was hoping you could help me on that too: 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

Thank you very much in advance for any suggestion, I would immensely
appreciate your help again. 

Arina




---- Original message ----
>Date: Mon, 9 Feb 2009 11:05:13 -0500
>From: "Steichen, Thomas J." <[email protected]>  
>Subject: RE: st: RE: data reorganization   
>To: "'Arina Viseth'" <[email protected]>
>
>   It's just another layer deeper...
>
>   qui gen newcountry = ""
>   qui gen newindice = .
>   qui gen newyear = ""
>   local j = 1
>   levelsof country, l(c)
>   foreach co of local c {
>     levelsof indice if country == "`co'", l(i)
>     foreach index of local i {
>       levelsof year if indice == `index' & country ==
>   "`co'", l(yrs) s(", ")
>       qui replace newcountry = "`co'" in `j'
>       qui replace newindice = `index' in `j'
>       qui replace newyear = "`yrs'" in `j'
>       local j = `j' + 1
>     }
>   }
>   -----------------------------------
>   Thomas J. Steichen
>   [email protected]
>   -----------------------------------
>
>   -----Original Message-----
>   From: Arina Viseth [mailto:[email protected]]
>   Sent: Monday, February 09, 2009 10:42 AM
>   To: Steichen, Thomas J.
>   Subject: Re: st: RE: data reorganization
>
>   Dear Mr. Steichen,
>
>   I was wondering if you could please help me one more
>   time. I would really appreciate your help once more.
>   I have another column "Country", and I would like to
>   do the exact same thing for each country.
>
>   i.e. instead of having
>
>   Country Indice Year
>   A        1      1990
>   A        1      1991
>   B        2      1993
>   B        3      1996
>   B        3      1997
>   C        1      1990
>
>   it would be:
>   Country  Indice  Year
>   A        1       1990,1991
>   B        2       1993
>   B        3       1996, 1997
>   C        1       1990
>
>   I am very grateful for your precious help yesterday.
>   Thank you very much in advance for your time.
>
>   Arina
>
>   ---- Original message ----
>   >Date: Sat, 7 Feb 2009 18:44:26 -0500
>   >From: [email protected] (on
>   behalf of "Steichen, Thomas J." <[email protected]>)
>   >Subject: st: RE: data reorganization
>   >To: "'[email protected]'"
>   <[email protected]>
>   >
>   >I can't imagine a reason for wanting this but the
>   following code will do so (but in new variables).
>   >
>   >levelsof indice, l(i)
>   >qui gen newindice = .
>   >qui gen newyear = ""
>   >local j = 1
>   >foreach index of local i {
>   >  levelsof year if indice == `index', l(yrs) s(",
>   ")
>   >  qui replace newindice = `index' in `j'
>   >  qui replace newyear = "`yrs'" in `j'
>   >  local j = `j' + 1
>   >}
>   >
>   >-----------------------------------
>   >Thomas J. Steichen
>   >[email protected]
>   >-----------------------------------
>   >
>   >-----Original Message-----
>   >From: [email protected]
>   [mailto:[email protected]] On
>   Behalf Of Arina Viseth
>   >Sent: Saturday, February 07, 2009 6:08 PM
>   >To: [email protected]
>   >Subject: st: data reorganization
>   >
>   >Dear all,
>   >
>   >I have a question regarding how to re-organize my
>   data on stata.
>   >
>   >Here is how the data currently looks:
>   >
>   >Indice Year
>   >1      1990
>   >1      1991
>   >2      2000
>   >2      2001
>   >2      2003
>   >3      1995
>   >3      1996
>   >4      2002
>   >
>   >Would it be possible to re-arrange the data so that
>   I would have the following:
>   >
>   >Indice  Year
>   >1       1990, 1991
>   >2       2000, 2001, 2003
>   >3       1995, 1996
>   >4       2002
>   >
>   >
>   >Any suggestion would be very much appreciated.
>   Thank you in advance.
>   >
>   >Arina
>   >
>   >*
>   >*   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/
>   >
>   >CONFIDENTIALITY  NOTE:  This e-mail message,
>   including any attachment(s), contains information
>   that may be confidential, protected by the
>   attorney-client or other legal privileges, and/or
>   proprietary non-public information. If you are not
>   an intended recipient of this message or an
>   authorized assistant to an intended recipient,
>   please notify the sender by replying to this message
>   and then delete it from your system. Use,
>   dissemination, distribution, or reproduction of this
>   message and/or any of its attachments (if any) by
>   unintended recipients is not authorized and may be
>   unlawful.
>   >
>   >*
>   >*   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/
>
>     ------------------------------------------------
>
>   CONFIDENTIALITY NOTE: This e-mail message, including
>   any attachment(s), contains information that may be
>   confidential, protected by the attorney-client or
>   other legal privileges, and/or proprietary
>   non-public information. If you are not an intended
>   recipient of this message or an authorized assistant
>   to an intended recipient, please notify the sender
>   by replying to this message and then delete it from
>   your system. Use, dissemination, distribution, or
>   reproduction of this message and/or any of its
>   attachments (if any) by unintended recipients is not
>   authorized and may be unlawful.
*
*   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