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

# Re: st: generate variable versus define scalar, with conditional statement

 From annoporci To statalist@hsphsun2.harvard.edu Subject Re: st: generate variable versus define scalar, with conditional statement Date Tue, 15 Jan 2013 22:25:46 +0800

```See the review
```
```
Fantastic reference, thanks Nick.

```
```
Thanks a lot,

Patrick.

---
Patrick Toche.

On Tue, 15 Jan 2013 21:59:09 +0800, Nick Cox <njcoxstata@gmail.com> wrote:

```
```See the review in excruciating detail in

@article \{dm0055,
author = "Cox, N. J.",
title = "Speaking Stata: Compared with ...",
journal = "Stata Journal",
publisher = "Stata Press",
volume = "11",
number = "2",
year = "2011",
pages = "305-314(10)",
url = "http://www.stata-journal.com/article.html?article=dm0055";
}

Abstract.  Many problems in data management center on relating values
to values in other observations, either within a dataset as a whole or
within groups such as panels. This column reviews some basic Stata
summarize, by:, sum(), cond(), and egen. Several techniques exploit
the fact that logical expressions yield 1 when true and 0 when false.
Dividing by zero to yield missings is revealed as a surprisingly
valuable device.

http://www.stata-journal.com/article.html?article=dm0055

On Tue, Jan 15, 2013 at 1:52 PM, annoporci <annoporci@gmail.com> wrote:
```
```I doubt that you need to loop, but I am completely in the dark over
what it is that you want to do.

Nick
```
```

I'm generating indices starting at different dates, so I want to use the
value of the variable at some date of my choosing (not the first
```
date in the dataset!) to generate an index starting at, say, the value 1, by dividing all observations by that value. Very simple. Probably one-line
```of code or less.

;-)
```
```*
*   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/
```
```

--
Patrick Toche.
*
*   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/
```