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: Looping over datetimes for simultaneous variable generation


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Looping over datetimes for simultaneous variable generation
Date   Thu, 3 Oct 2013 10:48:13 +0100

There are several problems evident here, and I guess some latent too.

You don't refer to any `datetime' macro within the loop, so at best it
would do the same things, regardless of the loop.

The syntax ' ' means nothing to Stata. You may wish to evaluate
numeric constants on the fly, for which the syntax would be something
like  `=  tc(19aug2012 0:00:00)’

The constant tc(00:05:00) seems unlikely to be what you intend.

For an arbitrary numlist you need -foreach- not -forvalues-.

Those points aside, a better strategy might to explain what you want
to calculate, with enough about your data and some example data for
people to follow.
Nick
[email protected]


On 3 October 2013 10:18, Paul Balcombe
<[email protected]> wrote:
> I have a timeseries data set and I want to generate a number of variables that are conditional on each other and their previous values, so I want to create a value for the set of variables at each time period in my data. I thought I should use a forvalues command, but this is new to me and I have so far been unsuccessful: invalid syntax. below is the command I wish to make:
>
> forvalues datetime= ‘tc(19aug2012 00:00:00)’ (‘tc(00:05:00)’) ‘tc(18aug2013 23:00:00)’ {
>                 replace seen=seen[_n-1] if seen==. & seen3[_n-1]<seen[_n-1]
>                 replace segaspow=segaspow[_n-1] if seen==. & seen3[_n-1]<seen[_n-1]
>                 replace seen2=seen2[_n-1] if seen==. & seen3[_n-1]<seen[_n-1]
>                 replace seen3=seen2+seen3[_n-1] if seen==. & seen3[_n-1]<seen[_n-1]
> }
>
> I may be describing the datetime functions incorrectly.
> Thanks,
> Paul
> *
> *   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/

*
*   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