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

Re: st: store means as a new variable

From   Maarten buis <>
Subject   Re: st: store means as a new variable
Date   Sat, 23 Feb 2008 14:08:33 +0000 (GMT)

--- Wencke <> wrote:
> how can I store estimates of mean values as well as their standard 
> deviation as new variables in my dataset?
> This is the command for the mean-values, I am using:
> mean maxgrip, over(gender ph013_)

Given your choice of words I am assuming you do not want the standard
deviation of maxgrip but the standard error of the mean. The standard
deviation is a measure of the degree in which observations differ to
one another with respect to maxgrip, the standard error of the mean is
a measure of how precise the estimate of the mean is. 

There are various ways of doing what you ask. Which one is best depends
on what you want to do with it. First notice that -mean- is an
estimation command so all tricks discussed in (Newson 2003) and (Buis
2007) are available to you. You can also create a variable containing
the mean using -egen-. The -egenmore- package, downloadable from -ssc-
also contains a function for creating a variable containing the
standard error. To download -egenmore- type -ssc instal egenmore-.

The example below illustrates all three methods.

*------------- begin example ---------------
set more off
sysuse auto, clear
sort rep78
mean mpg, over(rep78)

// discussed in (Buis 2007)
b = st_matrix("e(b)")'
V = st_matrix("e(V)")
se = diagonal(cholesky(diag(V)))
b, se

by rep78: egen m = mean(mpg)
by rep78: egen se = semean(mpg)
list rep78 m se

// discussed in (Newson 2003)
parmest, norestore
*---------- end example ---------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

Buis, Maarten L. (2007), "Stata tip 54: Where did my p-values go?", The
Stata Journal, 7(4), pp.584-586.
(A pre-publication draft can be downloaded from ) 

Newson R. (2003) "Confidence intervals and p-values for delivery to the
end user." The Stata Journal, 3(3), pp. 245-269. 
(A pre-publication draft can be downloaded from )

Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
*   For searches and help try:

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