The variable names displayed at left are of unequal length.
In contrast I know that I would like the first column of numeric
results to be aligned vertically and to be a column in the strict
sense. Thus I specify "{col 22}", which is a SMCL directive.
See -help smcl-.
SMCL is Stata's own mark-up language. The name is a contraction of
SMCL Makes Cooler Logs (the documentation is in error on this point).
There is an alternative which would be to specify that the number of
spaces skipped depends on the length of the variable name,
but choosing a particular column is much easier.
Also, in this case 22 is empirically chosen, as none of the variable names
in the auto dataset is especially long. For other datasets
I would need to use a column greater than 22, or to consider
abbreviating the variable name.
In contrast, for the spacing between two columns of numeric results
my use of formats implies that each column (field) is of constant width,
so I know that I can just give so many spaces. In this case I do have
a simple alternative, which is to specify
columns for the start of each field using "{col #}", but that
would oblige me to do some arithmetic, which
seems too much like hard work.
So the laziness of the programmer is paramount here, except that
it works.
-dlist- from SSC is a moderately simple worked example showing
various similar tricks, including also abbreviations, trimmings
of leading and trailing spaces, display of variable labels
and display of value labels.
Nick
n.j.cox@durham.ac.uk
Nishant Dass
> Hi Nick,
>
> I have a small question about the loop that you provided
> below. What does the "{col 22}" do? I tried searching for
> it but couldn't find any explanation; it seems that you are
> providing the width of the column that contains `v'.
>
> If that is the case, then why can't we do the same for the
> subsequent columns containing "r(t)" (instead of providing
> some blank space with " ")? Is it because this second
> column isn't in text format?
>
> Sorry for the bother but a clarification would be helpful.
> --- Nick Cox <n.j.cox@durham.ac.uk> wrote:
>
> > In the case of t tests, a work-around is obtained
> > by noting that the results of
> >
> > regress <response> <binary variable>
> >
> > are equivalent to
> >
> > ttest <response>, by(<binary variable>)
> >
> > so that -outreg- or -estout- (which I think
> > you mean here rather than -estimates-) can then be
> > used.
> >
> > Alternatively, a knit-it-yourself approach is
> > very simple:
> >
> > . foreach v of var price-gear {
> > 2. qui ttest `v', by(foreign)
> > 3. di as txt "`v'" "{col 22}" as res %6.3f r(t) "
> > " %5.4f r(p)
> > 4. }
> > price -0.414 0.6802
> > mpg -3.631 0.0005
> > rep78 -6.016 0.0000
> > headroom 2.609 0.0110
> > trunk 3.268 0.0017
> > weight 6.246 0.0000
> > length 5.890 0.0000
> > turn 6.903 0.0000
> > displacement 6.597 0.0000
> > gear_ratio -8.476 0.0000
> >
> > The essentials:
> >
> > 0. Looping over a variable list.
> >
> > 1. -quietly- executing your statistical command.
> >
> > 2. Picking up r() stuff (or indeed e() stuff) left in
> > memory.
> > You can -return list- or -ereturn list- or read the
> > manual
> > entry.
> >
> > 3. -display-ing results, with some attention to layout
> > and
> > formats.
> >
> > The example above is the third iteration of a real
> > example. I
> > guessed lucky at r(p) and r(t) and then made changes to
> > the layout and formats.
> >
> > At this point you may want to transfer to your text or
> > word processor.
> >
> > Although I have mixed feelings about the program,
> > I note that -makematrix- from SSC gets you there
> > too:
> >
> > . makematrix , from(r(p) r(t)) : ttest price-gear,
> > by(foreign)
> >
> > p t
> > price .88738723 .14215113
> > mpg .00008982 -4.1688344
> > rep78 8.313e-08 -6.0162381
> > headroom .00494105 2.9071556
> > trunk .00055112 3.6288312
> > weight 2.047e-09 6.9268345
> > length 2.461e-08 6.3182882
> > turn 1.721e-10 7.5259982
> > displacement 3.629e-09 6.7875143
> > gear_ratio 1.590e-12 -8.6552193
> >
> > . makematrix results , from(r(p) r(t)) format(%6.3f) :
> > ttest price-gear, by(foreign)
> >
> > results[10,2]
> > p t
> > price 0.887 0.142
> > mpg 0.000 -4.169
> > rep78 0.000 -6.016
> > headroom 0.005 2.907
> > trunk 0.001 3.629
> > weight 0.000 6.927
> > length 0.000 6.318
> > turn 0.000 7.526
> > displacement 0.000 6.788
> > gear_ratio 0.000 -8.655
> >
> > In this case, it is fortunate that 3 d.p. work fairly
> > well for both p and
> > t values. But then with most statistical results 3 d.p.
> > often work well,
> > although we frequently show many more places as a matter
> > of social ritual.
> >
> > Nick
> > n.j.cox@durham.ac.uk
> >
> > Nishant Dass
> >
> > > Is anyone aware of a command (like "outreg" or
> > "estimates")
> > > that I could use to tabulate "ttest" or "median" test
> > > results?
*
* 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/