Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: time-series operator in -foreach- loop


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: time-series operator in -foreach- loop
Date   Tue, 2 Jul 2002 13:58:13 +0100

Finne Håkon
>
> With data -tsset- :
>
> . gen event = 0
>
> . foreach i in 1/10 {
>   2. replace event = 1 if D`i'.group==1
>   3. }
> D1 not found
> r(111);
>
> . replace event = 1 if D1.group==1
> (6589 real changes made)
>
> .
> Why doesn't -foreach- read D1. as a time series operator, and which is the
> better workaround?

I guess the problem here is not the obvious: it is
with the way -foreach- is involed, not with the time-series operator.

The two -foreach- syntaxes using -in- and -of- should
not be conflated.

Stata is probably trying to execute

... if D1/10.group==1

and failing because the numerator, -D1- is not
found.

More at Stata Journal 2(2), 202-222 (2002).

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index