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: Labelling output in 12 month rolling loops


From   Nick Cox <[email protected]>
To   [email protected]
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
work.

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")
0

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.

Nick

On Wed, May 11, 2011 at 9:46 PM, Coetsee.Jane <[email protected]> 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: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Wednesday, May 11, 2011 4:01 PM
> To: [email protected]
> 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 <[email protected]> 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 Rolling_RNFHA_Outlier1.tab, replace
>>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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