Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: generate variable versus define scalar, with conditional statement
From
"Seed, Paul" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: generate variable versus define scalar, with conditional statement
Date
Thu, 17 Jan 2013 10:02:46 +0000
Just realised I had a typo:
It should be r(N), not r(n).
The correct version is:
clear all
sysuse sp500
summ open if date == mdy(1,2,2001), meanonly
/// the meanonly option suppresses output, and saves computer time
///by not calculating the standard deviation. It is not essential.
scalar newscalar_mean = r(mean)
scalar newscalar_min= r(min)
scalar newscalar_max= r(max)
if r(N) == 1 scalar newscalar = r(mean)
else scalar newscalar = .
/// And to check it:
summ open if date == mdy(1,2,2001)
scalar list
/// and with repeats
summ open if _n < 10, meanonly
/// the meanonly option suppresses output, and saves computer time
///by not calculating the standard deviation. It is not essential.
scalar newscalar_mean = r(mean)
scalar newscalar_min= r(min)
scalar newscalar_max= r(max)
if r(N) == 1 scalar newscalar = r(mean)
else scalar newscalar = .
/// And to check it:
summ open if _n < 10
scalar list
Paul T Seed, Senior Lecturer in Medical Statistics,
Division of Women's Health, King's College London
Women's Health Academic Centre, King's Health Partners
(+44) (0) 20 7188 3642.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/