  st: Re: storage type problem

 From "Michael Blasnik" To Subject st: Re: storage type problem Date Fri, 28 Feb 2003 11:19:06 -0500

```Theproblem is one of order of evaluation, not storage type.  (I have assumed
that you meant ^ wherever you typed * in your email)

When you type:
display -.1796042^4.752947

Stata calculates -(.1796042^4.752947) because the power takes precedence
over the negative sign.

When you have x=-.1796042 and y=4.752947 and then type:

gen z=x^y

Stata evaluates:

(-.1796042)^4.752947

and produces a missing value because you can't take fractional powers of
negative numbers --although answers may exist for ones such as (-8)^(1/3).
I think there was a thread on this a while back.

A work around for you would be :

gen z=sign(x)*abs(x)^y

Michael Blasnik
michael.blasnik@verizon.net

----- Original Message -----
From: "Kostova Deliana (HXX1DAK)" <HXX1DAK@ups.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, February 28, 2003 10:44 AM
Subject: st: storage type problem

> Hi everyone-
>
> I ran into the following small problem that, I think, has to do with
storage
> types, but I'm not sure how to solve it...
>
> Suppose we want to calculate the product of -.1796042 and 4.752947, so we
> type:
> display -.1796042^4.752947
> and we get
> -.00028563
>
> However, if we have variable X= -.1796042 and variable Y=4.752947, and we
> type
> gen Z=X*Y, Stata will generate Z=. even though Z should be -.00028563.
>
> I know this has to do with storage types, so i tried
> gen double Z=X*Y, but this still produces a missing variable...
>
> thanks a lot!
>
> Deliana
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```