Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Labelling output in 12 month rolling loops

From   Nick Cox <>
Subject   Re: st: Labelling output in 12 month rolling loops
Date   Wed, 11 May 2011 22:30:09 +0100

As the help for -twithin()- explains, it depends on a previous
-tsset-, so calling it when you have not -tsset- the data just won't

2009m2m1 is presumably a typo for something else.

You can say things like

... if inrange(string(yearmonth, "%tm"), "2007m12" , "2009m2")

quite independently of any -tsset-, but that's not reliable as

. di ("2007m9" < "2007m10")

shows, so I can't think of a one-to-one substitute for -twithin()-
without -tsset-.

As I said, I don't use -eststo- or -esttab- so cannot advise how to
use them best. Others may be able to help if they also understand
exactly what you are trying to do.


On Wed, May 11, 2011 at 9:46 PM, Coetsee.Jane <> wrote:
> OK, so I have converted yearmonth to a date format using -%t-.
>        format yearmonth %tm
> and the variable looks like this:
>   786. |   2007m6 |
>   787. |   2007m6 |
>   788. |   2007m6 |
>   789. |   2007m6 |
>   790. |   2007m6 |
> I can't use the -tsset- command because I have multiple observations per year.
> When I try to get a total using:
>        total Outlier_R_NotFHA if twithin(2007m12 , 2009m2m1) & Outlier_R_NotFHA==1
> I get the message:
>                 time-series operators not allowed
> do I need to total the observations by date to get a series of rolling totals?  Or is there a more elegant way?
> Thank-you,
> -Jane.
> -----Original Message-----
> From: [] On Behalf Of Nick Cox
> Sent: Wednesday, May 11, 2011 4:01 PM
> To:
> Subject: Re: st: Labelling output in 12 month rolling loops
> There are problems on several levels here.
> 1. The command that is failing is
>              label val `i' lbl
> as when first called that takes the form
>             label val 1 lbl
> which is quite illegal.
> 2. Before that, the line
>                label define lbl `i' "'T'", modify
> is legal but always assigns the text 'T' to a value label. Presumably
> your intention was to use the local macro T, which would be achieved
> with the call `T' (the important difference is the opening left
> quotation mark `). But as you defined the local macro T earlier the
> effect would be that _every_ value label would just be the literal
> text "in date". There is absolutely no way that would achieve the
> effect you desire of going off to look in the variable -date-; that is
> just fantasy syntax.
> 3. The -if- qualifier
> if yearmonth>= 576+`i' & yearmonth<588+`i'
> just will not work as Stata will not do calculations on the fly in
> this way, although there are other ways to do it.
> 4. You are evidently using user-written commands -eststo- and
> -esttab-, which you are asked to explain, saying where they come from.
> I don't use them, and can't provide support on how to use them.
> All that said, the issue appears to be labelling your months with
> intelligible dates. Just arranging that -yearmonth- has an appropriate
> date format (see -help format-) and exporting that together with your
> other variables is presumably the way forward. There is no need to
> write a loop to do that.
> Nick
> On Wed, May 11, 2011 at 2:57 PM, Coetsee.Jane <> wrote:
>> I am running 12 month rolling totals on the dummie variables
>> representing outliers for a model.  The variable "yearmonth" is a
>> numeric stata date type variable and "date" is a string variable that I
>> want to use as  labels for the output.   The problem with my 12 month
>> rolling code is that it produces a file with the totals I want but
>> without dates stating to which year end the total corresponds.  I am
>> trying to do this using the "label" command.  When I run the code below
>> I get the error message "1 invalid name"
>> local T in date
>> eststo clear
>> qui foreach i of num 1/24 {
>>                 label define lbl `i' "'T'", modify
>>                 label val `i' lbl
>>                 eststo:total Outlier if yearmonth>= 576+`i' &
>> yearmonth<588+`i' & Outlier_R_NotFHA==1
>>                 }
>>                 }
>>                 esttab using, replace

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index