Statalist The Stata Listserver


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

Re: st: RE: RE: means of dependent variables in estout


From   Matthew Pearson <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: means of dependent variables in estout
Date   Tue, 31 Oct 2006 16:09:50 -0800

Wow, that's much easier.  Thanks for the tip.

Matthew

On Oct 31, 2006, at 3:42 PM, Ben Jann wrote:

I'd like to point out two things:

- Matthew uses old -estadd- syntax in his example. Please
  update (-ssc install estadd, replace-) and see -help estadd-.

- The command

  . estadd ysumm

  adds the mean and standard deviation (and other statistics)
  of the dependent variable to e().

Therefore, to report the mean and standard deviation of the
dependent variable in -estout-, you may type something like

. sysuse auto, clear
. regress price weight mpg
. estadd ysumm
. estout, stats(ymean ysd)
        .
        b
weight  1.746559
mpg     -49.51222
_cons   1946.069
ymean   6165.257
ysd     2949.496

ben

Nick wrote:
Few first posts include two programs!

An important detail is that these programs
calculate results for all available values
of the dependent variable, regardless of what
was used in the model. You probably need
an -if e(sample)- restriction in each case.

Otherwise there is scope for cutting out middle macros:

program estadd_mu, eclass
 	syntax [ , prefix(name) * ]
 	su `e(depvar)' if e(sample), meanonly
 	ereturn scalar `prefix'mu = r(mean)
end

program estadd_sig, eclass
 	syntax [ , prefix(name) * ]
 	su `e(depvar)' if e(sample)
 	ereturn scalar `prefix'sig = r(sd)
end

Also, "sig" is an ambiguous name for a program.
I guess you have in mind "sigma" as the conventional
symbol for a population s.d. But "sig" means
"significance level" (i.e. P-value)
to many, perhaps more than it does "sd".
Matthew wrote:
Hi all,

This is my first post, so please bear with my if I have made some
mistakes.  I spent some time with a colleague yesterday trying to
figure out how to get estout to report the means and standard
deviations of the dependent variables in the stats option, with r-
squared and N, etc.  This proved to be quite a bit different from
reporting the means of the regressors, which is detailed in the
instructions.  I thought I would post how I did it in case anyone
else found it useful.  If there is a better way that anyone knows of,
then perhaps you can correct me, but this worked for me, and I could
not find a simpler way to do it.

*First, we create a subroutine (which I called "mu" and "sig"
respectively) to get the means and SDs from r( ) to e( ):

program estadd_mu, eclass
	syntax [ , prefix(name) * ]
	local depvar=e(depvar)
	sum `depvar'
	local mu=r(mean)
	ereturn scalar `prefix'mu = `mu'
end

program estadd_sig, eclass
	syntax [ , prefix(name) * ]
	local depvar=e(depvar)
	sum `depvar'
	local sig=r(sd)
	ereturn scalar `prefix'sig = `sig'
end

*Next, we use estadd, after the regression(s), and before estout, to
add the stats we generated to the stored estimates:

estadd [depvarlist], stats(mu sig)

*And finally, in the estout command, add mu and sig to the stats( )
option, along with other stats you may want.

That's all.  I hope this is helpful.

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