Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

RE: st: How to set a year index?

From   Nick Cox <>
To   Nick Cox <>, "''" <>
Subject   RE: st: How to set a year index?
Date   Fri, 20 May 2011 16:37:07 +0100

Sorry; Oliver's code was not 

local mean = 


local basevalue = 

so my point included a distortion of what he wrote. I think there remains scope for discussion about style, but I should have not misquoted Oliver's code. 


-----Original Message-----
From: Nick Cox 
Sent: 20 May 2011 16:25
To: ''
Subject: RE: st: How to set a year index?

We're talking style, and long ago wise people warned de gustibus non est disputandum. 

But, sincerely...

How does the extra code make it easier to understand? The presumption is that a reader needs the clue 

local mean = r(mean) 

to realise that r(mean) contains the mean. Really??? Reminds me of those places that give you warnings about hot drinks being hot. Also, the price is confusion for anyone who has no idea what a local is. So, the target readership is: people who know about locals, but not about means. 

The -scalar- is no more necessary than the -local-. 

I agree: -meanonly- is likely to have a trivial efficiency effect here. But it's worth learning about, and telling other people about, for problems where it matters. 


Oliver Jones

On 20.05.2011 16:58, Nick Cox wrote:

> The logic here is fine, but why do it this way?
> summarize price if year == 2005, meanonly
> gen price_index = price/r(mean)
> Note how
> 1. The middle macro is completely unnecessary.

I used the macro to make the code more readable/understandable.

> 2. Although it will not usually bite, you are probably losing asmidgen of precision by using a local.

Good point! I'm not sure, but I think the use of a scalar can solve the precision
problem of the local. So my code would be

scalar base_value = r(mean)
gen price_index = price/base_value

> 3. Specifying -meanonly- is efficient if all you need is the mean.

I'm not an expert on computing efficiency, but I wouldn't expect to
see a difference in execution time when -summarize-ing one single
But I admit that it is good style to use the meanonly option.

> Small points indeed, but in computing the devil is often in the details.
> Nick

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index