Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: Macro display format


From   Nick Winter <nw53@cornell.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Macro display format
Date   Thu, 23 Mar 2006 08:02:51 -0500

rclass results (the stuff in r() ) is only guaranteed to be around immediately after the command that creates them--they do not necessarily persist. When you run another rclass program, or a program that itself calls an rclass program in doing its work, they will disappear.

In the course of its work, the -graph- command clears rclass results, whether or not you used anything from the rclass in your graph command.

If you want something to persist, assign it to your own local macro before the graph:

. sysuse auto, clear
. qui summ length
. local mymean = `r(mean)'

. twoway scatter length mpg, text(200 35 "Mean is `: %2.1f `mymean''")

. di `mymean'

--Nick Winter



At 05:57 PM 3/22/2006, you wrote:

Sorry if this is a silly question.

I did the following sequence of commands. I closed the scatter as soon
as it opened. No other commands.

Why does r(mean) go away after you use it in the scatter with the
formatting extended function?

. sysuse auto, clear
(1978 Automobile Data)

. quietly summ length

. di `r(mean)'
187.93243

. di `: di %9.1f `r(mean)''
187.9

. di `: di %9.1f `r(mean)''
187.9

. twoway scatter length mpg, text(200 35 "The mean of length is:`: di
%2.1f `r(mean)''")

. di `: di %9.1f `r(mean)''


. di `r(mean)'


.

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Wednesday, March 22, 2006 5:51 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: Macro display format

No. You should try

` : di %9.1f `r(mean)''

See help extended_fcn.

Tip: I would go `: di %2.1f `r(mean)'' even
if you are sure that format is too restrictive.
You're likely to be wrong, as Stata will stretch the space to
avoid damage. However, with %9.1f you are likely to get the ugly
spaces that are a consequence of what you asked
for.

Nick
n.j.cox@durham.ac.uk

Thomas Speidel

> I am trying to include the content of a macro within a graph, but I'm
> having problems with the display format.
>
> For example:
>
> sysuse auto, clear
> qui: summ length
> twoway scatter length mpg, text(200 35 "The mean of length is:
> `r(mean)'")
>
> How do I change the format of the macro to display something
> like %9.2f?
>
> I tried:
> ... , text(200 35 "The mean of length is: `%9.1f `r(mean)''")
>
> Am I missing some triple compound quote? :-)

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


This message is intended solely for the designated recipient(s). It may contain confidential or proprietary information and may be subject to confidentiality protections. If you are not a designated recipient, you may not review, copy, or distribute this message. If you receive this in error, please notify the sender by reply e-mail and delete this message.

Arrowstreet Capital, L.P. is an Equal Opportunity Employer.



*
* 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/
________________________________________________________
Nicholas J. G. Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government nw53@cornell.edu e
Cornell University falcon.arts.cornell.edu/nw53 w
308 White Hall
Ithaca, NY 14853-4601

*
* 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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index