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
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: generate variable versus define scalar, with conditional statement
Date
Thu, 17 Jan 2013 11:02:38 +0000
The code here uses the mean for -newscalar- if and only if there is
just one value, in which case the mean is just that one value.
Everything depends on what the code is trying to do, but in many cases
where I am summarizing data I am happy to use a constant as summary
when the data are indeed constant. Hence
if r(min) == r(max) scalar newscalar = r(mean)
This criterion necessarily is consistent with r(N) == 1.
On Thu, Jan 17, 2013 at 10:02 AM, Seed, Paul <[email protected]> wrote:
> 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 = .
*
* 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/