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

# Re: st: How to set a year index?

 From Oliver Jones To statalist@hsphsun2.harvard.edu Subject Re: st: How to set a year index? Date Fri, 20 May 2011 17:12:51 +0200

```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
observation.
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
n.j.cox@durham.ac.uk
```
```*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```