Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to standardize a variable with a define mean

From   Maarten Buis <>
Subject   Re: st: How to standardize a variable with a define mean
Date   Wed, 1 Feb 2012 10:48:07 +0100

On Wed, Feb 1, 2012 at 10:44 AM, Alberto R Osella wrote:
> I want to standardize a variable (BMI) with a given mean value. I've
> obtained that value from a -summarize- command, that is r(mean).
> Now I want to pass the value of r(mean) to the egen command. Here the
> commands and the error returned by Stata.
> . sum BMI
> . scalar meanbmi=r(mean)
> . display meanbmi
> 25.8435
> . egen stdbmi=std(BMI), mean(meanbmi) std(1)
> option mean() incorrectly specified
> r(198);


egen stdbmi=std(BMI), mean(`=meanbmi') std(1)

The trick is that meanbmi is the name of a scalar while the -mean()-
option expects a number. By surrounding that scalar name with " `= "
and " ' " you are forcing Stata to first evaluate the scalar name,
resulting in a number, which is exactly what the -mean()- option

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index