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]

Re: st: copying contents form existing to new variable


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: copying contents form existing to new variable
Date   Wed, 24 Apr 2013 15:07:38 +0100

So, as said, the two variables are numerically identical, but one has
a value label and the other doesn't.

The -list- clinches. (No differences between the variables means
nothing to show.)

Hence Stata is not changing anything, but you are seeing labels when
you -list-, by default.

The problem is yours to solve, and was not created by Stata. One
variable is labelled, but from the evidence that set of labels looks
strange.

. label li stooltested

to see what has been done to your data. (No; I don't want to see your
categories, thanks.)

Nick
[email protected]


On 24 April 2013 14:59, Patricia Biedermann <[email protected]> wrote:
> Thanks Nick for the quick reply.
>
> I imported the data from an excel file; some of them where imported as
> string variables and the labels came with importing too.
>
>
>
> No, - NumberExamined- doesn't have value label
>
> . describe total NumberExamined
>
>               storage  display     value
> variable name   type   format      label      variable label
> ----------------------------------------------------------------------------------------
> total           long   %8.0g       stooltested   number of stool tested
> NumberExamined  double %10.0g
>
>
> When I did the -list var1 var2 if var1 != var2- command it didn't show
> me any results....
>
> On Wed, Apr 24, 2013 at 3:46 PM, Nick Cox <[email protected]> wrote:
>> Your variables are, it may be guessed, numerically identical. See the
>> results of -summarize-.
>>
>> -total- has a value label, but -NumberExamined- seemingly doesn't.
>> (You don't show -describe- for that.)
>>
>> You didn't show any results for -list var1 var2 if var1 != var2- which
>> ignores the labels.
>>
>> Why do you need a value label for what looks numeric? Why was the
>> original a string  variable any way? Perhaps there were problems with
>> stray characters.
>>
>> Nick
>> [email protected]
>>
>>
>> On 24 April 2013 14:38, Patricia Biedermann <[email protected]> wrote:
>>> Hello Nick,
>>>
>>> I used the -clonevar- command. The contents remained the same, but if
>>> I do a simple calculation (cross multiplication) with var2 then the
>>> results are wrong
>>>
>>> Here are some results of the approach I used before:
>>> NumberExamined should be the copy of total
>>>
>>> list total NumberExamined
>>>
>>> total   NumberExamined
>>> 1.    51         38
>>> 2.  18        10
>>> 3.   20         12
>>> 4.   19         11
>>> 5.   55         41
>>> etc
>>>
>>> describe total NumberExamined
>>>
>>>                                storage        display     value  variable
>>> variablename         type              format      label   label
>>>
>>> total                       long               %8.0g     stool    stooltest
>>>
>>> su total NumberExamined
>>>
>>> Variable                     Obs        Mean    Std. Dev.       Min        Max
>>>
>>> total                             25       21.56     13.2164
>>> 1         45
>>> NumberExamined         25       21.56     13.2164          1         45
>>>
>>>
>>> On Wed, Apr 24, 2013 at 11:20 AM, Nick Cox <[email protected]> wrote:
>>>> This could be as simple as your new variable not inheriting the value
>>>> labels of the -encode-d variable. (Have a look at -clonevar-.)
>>>>
>>>> Otherwise, we need more evidence. What you do mean by the contents
>>>> changing? Show us the results of
>>>>
>>>> . describe var1 var2
>>>> . su var1 var2
>>>> . list var1 var2 if var1 != var2        [example at least]
>>>>
>>>> Nick
>>>> [email protected]
>>>>
>>>> On 24 April 2013 10:10, Patricia Biedermann <[email protected]> wrote:
>>>>
>>>>> If I generate a new variable from an existing variable it happens that
>>>>> the contents get changed.
>>>>> gen var2=var1
>>>>>
>>>>> My approach is following:
>>>>> 1) My original variable is string and I - encode - it: var1
>>>>> 2) gen var2=var1
>>>>>
>>>>> At step 2) the contents changes.
>>>>> I came along this Thread:
>>>>> http://www.stata.com/statalist/archive/2012-05/msg01280.html
>>>>> ..and tried to create a double variable first before copying the
>>>>> variables. Anyway, the same problem appears again.
>>>>>
>>>>> What could be the problem? It did this thing (gen var2=var1) many
>>>>> times and it always worked so far...
>>>> *
>>>> *   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/
>>> *
>>> *   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/
>> *
>> *   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/
> *
> *   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/
*
*   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