Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Outreg for descrptive stats

From   "Nick Cox" <>
To   <>
Subject   st: RE: Outreg for descrptive stats
Date   Fri, 25 Jul 2003 17:22:14 +0100

This whole business -- let's call it the
reporting problem, namely, how best to produce, collate
and report a lot of related results -- is of course
of great concern to many users. It is much of what
most of us _do_ with Stata, perhaps most of what
some of us do, and all of what a few of us do.

One short answer to Ronnie's question is to check
out Roger Newson's paper on his set of programs.
That paper will be forthcoming in Stata Journal 3(3)
or Stata Journal 3(4), but a pre-publication copy
will no doubt be available somewhere soon, if not

Another short answer, and it is said
with my tongue only a little in cheek, is Yes.
The program is called Stata.

Let's put in context that John Gallup's very substantial
-outreg- project was focused on a class of related commands
and made possible by one basic principle, the generic similarity
of those commands, itself the result of a tight design in Stata.

What Ronnie wants to do here is
produce a lot of results from a lot of commands and select
some of the results and present them in
a neat way. A program to do that would have to be very
general and have to have lots of handles to cope with
even the simplest possibilities which might arise.
But that program exists. It is Stata itself.

Let me put it another way. We can fantasise about
the commands we would we like to see, and one
might be called -report-. You would specify to -report-
what commands you want to run on what variables
and what categories and which results you
want to keep and how you want to present them,
and no doubt other details, like you want -if-
and -in- and -by- and weights and what you do
with missing values.

What the syntax you want to type look like?
(I am not saying write the program. I am saying
_imagine_ the help file.)

Horrendous. That's my guess. It would be like trying
to lump a very large fraction of Stata into one command.

Here is another approach.

There is one basic bag of tricks which gets you
a long way:

cycle over variables with -foreach-

cycle over categories with -foreach- or -forvalues-

-quietly- issue <whatever> command

pick up the saved results you want

put them somewhere safe

process them as a new (part of the) dataset.

Here is a fairly simple example.

I rely on the fact that the number of observations
in the auto data set is more than the
number of variables. Something like that
is usually true. If not, there are other
ways to do this.

I cycle over the variables in the auto
dataset, and do t tests, -by(foreign)-.

0. Initialise

I need places to put results. I
am going to collect t statistics and
P values. If I initialise variables
by a -generate-, then I can -replace-
within a loop.

gen varname = ""
gen t = .
gen P_value = .
local i = 1

1. Cycle

ds, has(type numeric)

qui foreach v of var `r(varlist)' {
	capture ttest `v', by(foreign)
	if _rc {
		replace varname = "`v'" in `i'
		replace t = r(t) in `i'
		replace P_value = r(p) in `i'
		local ++i

2. What I have got?

list varname t P if t < .

Note: there are two loops here, executed
in unison. As soon as I have a result
to put in an observation, I bump up the
observation number. There is more about
this in "Problems with lists", Stata Journal
3(2), 2003.

Note: this is not Stata programming. Nowhere
did I write the word -program-. Admittedly,
you need to tricks from the programmer's
repertoire to do this well.


> -----Original Message-----
> From:
> []On Behalf Of Ronnie
> Babigumira
> Sent: 25 July 2003 16:23
> To:
> Subject: st: Outreg for descrptive stats
> Hi (stata8.1, win2k)
> A quick one, is there an equivalent of outreg for simple descriptive
> statistics? I am running a number of tests for diffrences
> in means across
> categories for a whole lot of variables. In addition, I am
> doing a number of
> cross tabulations. After this I cut and paste these into a
> table in a report
> however, how stata users are constantly on the look out for
> efficiency, I am
> thinking some one must have written a ado to automate this process.
> Does such a thing exist

*   For searches and help try:

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