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]
Re: st: reshaping + info from label
From
Abhimanyu Arora <[email protected]>
To
[email protected]
Subject
Re: st: reshaping + info from label
Date
Tue, 25 Oct 2011 03:31:43 +0200
Thanks a million as always, Nick, very useful -longshape- of yours, too .
PS-While matters are solved now, just to share my hazy idea- I thought
of a possibility to use the -ds- in a loop (given that the labels were
limited in no.) + reshape and making use of the fact that the variable
names are stored in r()...but anyway its immaterial now.
Thanks a lot indeed!
Best regards
Abhimanyu
On Tue, Oct 25, 2011 at 3:20 AM, Nick Cox <[email protected]> wrote:
> -whatever- in this example is created as a numeric variable with value
> labels, so you would need to -decode- it before you could apply
> -split-.
>
> Nick
>
> On Tue, Oct 25, 2011 at 1:59 AM, Nick Cox <[email protected]> wrote:
>> That made it clearer. You can do this
>>
>> clear
>> input date str1 variable1ab str1 variable2cd
>> 1 q w
>> 2 e r
>> end
>> label var variable1ab "A B"
>> label var variable2cd "C D"
>> save aroratest
>> longshape variable*, i(date) j(whatever)
>>
>> . l
>>
>> +-----------------------------------+
>> | date whatever _whatever y |
>> |-----------------------------------|
>> 1. | 1 A B variable1ab q |
>> 2. | 1 C D variable2cd w |
>> 3. | 2 A B variable1ab e |
>> 4. | 2 C D variable2cd r |
>> +-----------------------------------+
>>
>> It then sounds like a case for -split- on -whatever-.
>>
>> The key to this solution was posted fairly recently, -longshape- from SSC.
>>
>> -ds- and -findname- find variable names, but string values within the
>> data are not where it looks. I still see no connection with this
>> problem, despite being very familiar with both commands, but if
>> -longshape- helps with a solution, I guess that is immaterial.
>>
>> Nick
>>
>>
>> On Tue, Oct 25, 2011 at 1:46 AM, Abhimanyu Arora
>> <[email protected]> wrote:
>>
>>> Thanks Nick, let me pls elaborate the problem.
>>> The reason why -ds- or your -findname- come into the picture is
>>> because I would like to take some strings out of the variable label
>>> and place them into the data.
>>> So let us consider only one variable variable1ab. "A B" is the
>>> variable label for the variable variable1ab and I would like to create
>>> 2 new variables taking up the values (two strings from the label) A
>>> and B and the third variable takes up the original value of the
>>> variable. The reason for all this is that I would eventually like to
>>> take some correlations -by- A and B (this information is available in
>>> the variable label).
>>>
>>> On Tue, Oct 25, 2011 at 2:10 AM, Nick Cox <[email protected]> wrote:
>>>> You don't show what you tried with -reshape-. If these were string
>>>> variables, then you can go
>>>>
>>>> input date str1 variable1ab str1 variable2cd
>>>> . 1 q w
>>>> . 2 e r
>>>> end
>>>> reshape long variable, i(date) string
>>>> l
>>>>
>>>> +-----------------------+
>>>> | date _j variable |
>>>> |-----------------------|
>>>> 1. | 1 1ab q |
>>>> 2. | 1 2cd w |
>>>> 3. | 2 1ab e |
>>>> 4. | 2 2cd r |
>>>> +-----------------------+
>>>>
>>>> I don't follow what you are trying to explain about labels. Value
>>>> labels? Variable labels? Nor do I follow what the connection with -ds-
>>>> or -findname- (SJ) is here.
>>>>
>>>> Nick
>>>>
>>>> On Tue, Oct 25, 2011 at 12:11 AM, Abhimanyu Arora
>>>> <[email protected]> wrote:
>>>>
>>>>> I am trying to reshape data that has the following form---
>>>>>
>>>>> date variable1ab variable2cd
>>>>> 1 q w
>>>>> 2 e r
>>>>>
>>>>>
>>>>>
>>>>> Assume the variable variable1ab is labelled A B, while variable2cd is
>>>>> labelled C D (actually strings, though)
>>>>>
>>>>>
>>>>> Finally I would like the data to be of the following form
>>>>>
>>>>> date var1 var2 value
>>>>> 1 A B q
>>>>> 2 A B e
>>>>> 1 C D w
>>>>> 2 C D r
>>>>>
>>>>>
>>>>> I feel the solution might lie in the commands -ds- or Nick Cox's
>>>>> -findname- together with -reshape- but I am just unable to see how.
>>
>
> *
> * 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/