Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Problem with power operator


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: RE: Problem with power operator
Date   Wed, 28 Aug 2002 08:59:18 -0400

> Dear Stata users
> 
> Using 
> 
> . do "... \square.do"
> 
> . program define square
>   1. version 7.0
>   2. gettoken n 0 : 0, parse(" ,")
>   3. local nsquared1=`n'^2
>   4. local nsquared2=(`n'*`n')
>   5. di "`nsquared1'   `nsquared2'"
>   6. end
> . 
> end of do-file
> 
> I observe the following misbehaviour of the power operator "^2"
> 
> . square -2
> -4   4
> 

This is because the power operator takes precedence over the negation
operator.  Compare:

di  -2^2
di (-2)^2

So if you edit your square program accordingly, you should be fine.

Nick Winter
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index