Bookmark and Share

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   Tue, 15 Jan 2013 14:35:42 +0000

It is the same logic. For

scalar newscalar = open[3jan2012]

to work, 3jan2012 has to make sense as a subscript, and it doesn't.
Stata's message is likely to refer to time-series operators, which is
Stata's guess at what a mix of letters and numbers might be here.

There are various Stata and Mata contexts in which names or strings
can make sense as subscripts, but this isn't one of them.

Nick

On Tue, Jan 15, 2013 at 2:25 PM, annoporci <[email protected]> wrote:
>> 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.
>
> Your suggestion to:
>
> 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 <[email protected]> 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
>> of your dataset.
>>
>> 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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index