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".
Nick
n.j.cox@durham.ac.uk
Matthew Pearson
> 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/