Statalist


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

Re: st: RE: AW: rounding a tempvar


From   "Cathy L. Antonakos" <[email protected]>
To   [email protected]
Subject   Re: st: RE: AW: rounding a tempvar
Date   Tue, 23 Jun 2009 14:12:42 -0400 (EDT)

Thanks Martin and Nick for your helpful advice.

Cathy


On Tue, 23 Jun 2009, Nick Cox wrote:

Date: Tue, 23 Jun 2009 18:24:00 +0100
From: Nick Cox <[email protected]>
Reply-To: [email protected]
To: [email protected]
Subject: st: RE: AW: rounding a tempvar

The reason you got the problem you got is precision. The variable you
created holds a value as close to .71 as is possible, but there is no
exact binary equivalent. But as Martin implies you needn't use new
variables and you should just specify a format.

Nick
[email protected]

Martin Weiss

Use "macro extended functions" as in - help extended_fcn-

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

corr

di in red `r(rho)'
di in red %3.2fc `r(rho)'

local wcorr: /*
*/ di %3.2fc `r(rho)'

di `wcorr'
*************

Cathy L. Antonakos

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


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