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:56 +0800

```scalar newscalar = open[mdy(1,3,2012)]

is

scalar newscalar = open[18995]
```
```

yes, I see, absolutely, I did try this also:

scalar newscalar = open[3jan2012]

```
but it didn't work, even after a tsset date, and there must be a logical explanation for that too, naturally, but I guess I ran out of ideas and stopped thinking.
```

su `var' if date == mdy(1,3,2012), meanonly
scalar `var'_ini = r(min)

works inside my loop over the list of variables `var', so that's what I'm
using now

That's better than generating mostly-missing variables, I'm sure.

thanks Nick!

On Tue, 15 Jan 2013 22:07:42 +0800, Nick Cox <njcoxstata@gmail.com> wrote:

```
```It does work; it's just not what you want.

Stata is perfectly logical here.

scalar newscalar = open[mdy(1,3,2012)]

is

scalar newscalar = open[18995]

which will be missing or some value, depending on the size and details

Stata is very good at syntax, but it's lousy at semantics. You want
Stata to be like a smart research assistant  and to look at
mdy(1,3,2012) and to realise what you _mean_, which is to go and find
the observation for that date, etc. Stata only notices what you _say_.

But no; Stata is a robot and just evaluates -mdy(1,3,2012)- as a pure
number, which is then treated as a subscript or observation number.
Again, that is what you said as far as it is concerned.

On Tue, Jan 15, 2013 at 1:47 PM, annoporci <annoporci@gmail.com> wrote:
```
```you write faster than I think Nick!
```
```
[...] I need to be
```
```able to specify the date in a "human readable" way, so I tried:

scalar newscalar = open[mdy(1,3,2012)]

It doesn't work.
```
```*
*   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/
```