Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Aw: st: RE: Reshape from long to wide and attaching Labels contained in a Variable.


From   "Stefan Schöftner" <[email protected]>
To   [email protected]
Subject   Aw: st: RE: Reshape from long to wide and attaching Labels contained in a Variable.
Date   Fri, 30 Aug 2013 02:20:53 +0200 (CEST)

First of all ty for all the imput so far, and sorry for my kinda incompetent way of asking...
i try my best to answer all the questions from before and reroll the Question itself.

1st.
The double yy4 was a typo, i have to appologise for that.
My Data set is looking like this in long form:


Obs. ID     Title  Amount  Code
1    xxx     abc   12345   yy1
2    xxx     bcd   54321   yy2
3    xxx     cda   43215   yy3
4    xxx     acb   32154   yy4
5    xxx     cad   21543   yy5

2nd.
My goal is to reshape it into wide form because i need unique ID´s for further merging with other datasets with additional information.

3rd
i reshaped using the command:

reshape wide  Amount, i(ID)  j(Code)

The result looks like this

Obs. ID     yy1     yy2    yy3     yy4     yy5   Title

1    xxx   Amount                                abc
2    xxx            Amount                       bcd
3    xxx                  Amount                 cda
4    xxx                          Amount         acb
5    xxx                                 Amount  cad

And yes, this would lead to an error, like sarah pointed out, if i had 2 or more identical ID´s in my sample.

Therefore i can simply drop Title before reshaping and forget all about what i wanted to do or use sarah´s command.: 

reshape wide title amount, i(id) j(code)

it would look like this:

Obs. ID     yy1    yy1Title    yy2  yy2Title    yy3    yy3Title    yy4  yy4Title   yy5   yy5Title

1    xxx    Amount  abc
2    xxx                    Amount   bcd
3    xxx                                      Amount    cda
4    xxx                                                         Amount  acb
5    xxx                                                                          Amount  cad

4th-
What i´m trying to achiev is now that Titel values are now represented int the variable List as Variable Lables

Such as:

Variable                   Label
ID                     Identification Nr.
yy1                    (yy1Title) yy1 abc 
yy2                    (yy2Title) yy2 bcd
and so forth

5th.

I also have to mention since the ID´s repeat it will happen that there are variouse Amounts listed among one ID
so it will Look like this with sarahs reshape code:

Obs. ID     yy1    yy1Title    yy2  yy2Title    yy3    yy3Title    yy4  yy4Title   yy5   yy5Title

1    xxx    Amount  abc       Amount   bcd  
2    xxx    Amount  abc       Amount   bcd
3    xxx    Amount  abc       Amount   bcd      Amount    cda
4    xxx                      Amount   bcd      Amount    cda     Amount  acb
5    xxx                      Amount   bcd      Amount    cda     Amount  acb      Amount  cad


I hope this makes my intentions clear now.


I still have to try Phils suggestion of how to solve my Problem, but 2 am aint the time for that i think.

Thanks again to all of you for going through the trouble of helping a new one.

Best Regards 
Stefan



Gesendet: Freitag, 30. August 2013 um 01:31 Uhr
Von: "Sarah Edgington" <[email protected]>
An: [email protected]
Betreff: st: RE: Reshape from long to wide and attaching Labels contained in a Variable.
Stefan,
It would be helpful to see what the actual command you used to reshape your data was. Either the example you're showing below isn't what your data actually looks like or there's a lot you aren't saying about the reshaping process.
I'm assuming you reshaped with code something like:
reshape wide title amount, i(id) j(code)
However, your example can't be reshaped that way since code repeats within an ID. Plus your example doesn't include a reshape of Title (which, again, will produce an error if you try to reshape the example you show).

If you show actual code and example data that has the same structure as your real data someone may be able to offer more specific advice. As it is, what you've given here isn't enough for me to grasp what you've accomplished so far, much less exactly what you're trying to accomplish.

Given the example you've shown, what you want to do seems impossible to me. You have a single code "yy4" with two different titles. How would you decide which label the final yy4 variable gets (I'm assuming what you're trying to do is attach variable labels; I may be wrong about that)?

-Sarah

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index