Statalist


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

st: AW: rounding a tempvar


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: rounding a tempvar
Date   Tue, 23 Jun 2009 18:41:57 +0200

<> 


Note that a -tempvar- would have represented waste here as all you want is a
single value: You are better off with a -local-.

Also note that the result observed by Cathy probably hinges on her -set
type- behaviour. Stata assumes a certain default -data type- for a new
variable in a -generate- statement which she can find by typing -query
other-. As soon as you ask -generate- for a more memory intensive storage
type, such as -double-, the result is correct. Note how the waste of a
-tempvar- vs. a -local- multiplies by the number of observations in your
dataset in this case...

Last but not least, -display- gives you the first observation of a variable
by default so no error message alerts you to the waste...

***

clear*
drawnorm x y, n(100) /* 
 */ corr(1,0.71 \ 0.71, 1) /* 
 */ cstorage(full)

corr

tempvar wcorr1 wcorr2 wcorr3

gen byte `wcorr1' =/* 
 */  round(`r(rho)', .01)
gen float `wcorr2' =/* 
 */  round(`r(rho)', .01)
gen double `wcorr3' =/* 
 */  round(`r(rho)', .01)

display `wcorr1' " " /* 
 */ `wcorr2' " " /* 
 */ `wcorr3' " "

***



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Cathy L.
Antonakos
Gesendet: Dienstag, 23. Juni 2009 18:18
An: [email protected]
Betreff: st: rounding a tempvar

Dear Statalist,

I want to display a correlation on a graph, rounded to 2 decimal places. A
new, temporary variable, generated as follows, does not produce the rounded
correlation I expect (r = 0.71).

. corr wandurav wanrate
(obs=177)

              | wandurav  wanrate
-------------+------------------
     wandurav |   1.0000
      wanrate |   0.7085   1.0000

. display `r(rho)'
.70846375

. tempvar wcorr

. gen `wcorr' = round(`r(rho)', .01)

. display `wcorr'
.70999998


There must be a simple way to do this. 
Thanks for your help.
Cathy

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



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