Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: Control of format in output of commands?


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Control of format in output of commands?
Date   Thu, 3 Feb 2011 19:42:18 +0000

What you do in -format- doesn't carry over to -summarize-. That's the way it's written. You can get round it, with more or less work, by just picking up the results and spitting them out in whatever format you like. Here's a miniature illustration: 

program state_of_the_art 
	version 8.2 
	syntax varname(numeric) [if] [in] 

	qui su `varlist' `if' `in'
	di "mean " %9.2f r(mean)
	di "SD   " %9.3f r(sd)
	di "min  " %9.2f r(min)
	di "max  " %9.2f r(max) 
end 

. state_of_the_art mpg
mean     21.30
SD       5.786
min      12.00
max      41.00

But any way, why should -format- carry over to -summarize-? It so happens, as you know, that mean, SD, min and max all have the same units as the original variable. But even so, that is not compelling. In the case of -mpg- the values are integers and I might be happy with a format that insists on that for showing raw data. But even the median might be something and a half, I might want some decimals for the mean, the variance has different units, and it is most unlikely that skewness and kurtosis (unit-free) will be integers. 

The bottom line is important: Ultimately, if you don't like a default format, you can always write your code to show things exactly as you want. But it's hard for Stata to know what you might want across a range of quite different results. 

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

Art Burke

I'm using Stata/MP 11.1 on Windows 7.

Could someone kindly explain the control of the print formats in the following?

.sysuse auto

. mean mpg

Mean estimation                     Number of obs    =      74

--------------------------------------------------------------
             |       Mean   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
         mpg |    21.2973   .6725511       19.9569    22.63769
--------------------------------------------------------------

. set cformat %9.2f

. mean mpg

Mean estimation                     Number of obs    =      74

--------------------------------------------------------------
             |       Mean   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
         mpg |      21.30       0.67         19.96       22.64
--------------------------------------------------------------


. summarize mpg

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
         mpg |        74     21.2973    5.785503         12         41                  
      
. format mpg %9.2f

. summarize mpg

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
         mpg |        74     21.2973    5.785503         12         41       



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index