rename dummy and diagonal dummy

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Thu Apr 06, 2017 10:49 am

Hello,

The first "period" of the series will be NAs, e.g., (NA, NA, NA, 1, 2, 3, 1, 2, 3, ...), because @day(-1) is NA for the first observation. That causes @day<>@day(-1) to evaluate to NA instead of true. NA is interpreted as false, therefore @recode assigns tx(-1) + 1, which is also NA, to the first observation of tx. For the rest of the first period @day<>@day(-1) is false, so @recode continues to assign tx(-1) + 1 to subsequent observations of tx, which just propagates the NA. Only when you hit the second period is @day<>@day(-1) true, and things work correctly from that point onward. The problem is the first evaluation of @day(-1) that evaluates to NA, but you can easily change your @recode condition in many ways to handle that special case. For example,

Code: Select all

series tx = @recode(@day<>@day(-1) or @isna(@day(-1)), 1, tx(-1) + 1)

clubmed
Posts: 81
Joined: Sun Nov 30, 2014 3:03 am

Re: rename dummy and diagonal dummy

Postby clubmed » Thu Apr 06, 2017 1:49 pm

Got it!.
last question: but if i generate a series break trend with this code
series break=@recode(@during("2000m01 2001m05") or @during("2003m10 2004m12") or @during("2006m01 2007m04") or @during("2008m01 2015m02"),1,0)
break=@recode(@during("2005m01 2005m07") or @during("2005m10 2005m12") or @during("2007m01 2007m04") or @during("2008m01 2009m02"),beark(-1)+1,0)
i get "NA" from 2000m01 to 2001m05 in my series, but from 2003m10 2004m12... i get what's i need (break trend) , if i use in the first code @cumsum(1) (normally @cumsum(1) solve this directly) the trend continue (e.g 1 2 3 0 0 4 5 6 0 0 0 0 0 6 7...etc), how can fix this by one way.

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Thu Apr 06, 2017 3:20 pm

Odd. There aren't any NAs in the series when I run those two lines (after fixing the typo near the end of the second line, "beark" -> "break").

clubmed
Posts: 81
Joined: Sun Nov 30, 2014 3:03 am

Re: rename dummy and diagonal dummy

Postby clubmed » Fri Apr 07, 2017 2:16 am

sorry,
if i use this code:
series break=@recode(@during("2000m01 2001m05") or @during("2003m10 2004m12") or @during("2006m01 2007m04") or @during("2008m01 2015m02"),break(-1)+1,0)
from 2000m1 to 2001m05 it start by "NA" from 2000m01 to 2001m05.
how can fix this by one way (i know that i can fix this by Edit)?

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Fri Apr 07, 2017 8:52 am

This is the same fundamental problem as your previous series tx, in this case it's break(-1) evaluating to NA at the first observation. You can fix the issue in much the same way, or for variety:

Code: Select all

series break=@recode(@during("2000m01 2001m05") or @during("2003m10 2004m12") or @during("2006m01 2007m04") or @during("2008m01 2015m02"), @nan(break(-1), 0) + 1, 0)

clubmed
Posts: 81
Joined: Sun Nov 30, 2014 3:03 am

Re: rename dummy and diagonal dummy

Postby clubmed » Fri Apr 07, 2017 10:19 am

I don't know how to thank you, you make a great job, your help is very useful, i wish you great success in the future "EViews Matt". :D
I will thanks "Mr Gareth" too.

ecofin
Posts: 182
Joined: Fri May 10, 2013 11:24 am

Re: rename dummy and diagonal dummy

Postby ecofin » Fri Apr 07, 2017 2:13 pm

Hi everybody,

I would have a follow up question on that: "De-trending with a level shift and/or a broken trend", i have several series that contaned multiple break points, to solve this it is necessary two have two series level shift and broken trend.
1) how can reverse the series d_.... in the previous programs that will be trend ( by one month or by spanning two month... or by week when spanning two weeks or 3 weeks...): e.g. 1 2 3 4 5...
2) same to the first question but trend be T=(1111 2222 3333....) the reason "T" takes this rather odd form is that, when it is multiplied by the seasonal dummies, the resulting trending dummies always sum to zero over each year.

Kind Regards.

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Fri Apr 07, 2017 3:43 pm

Hello,

I'm unsure what you mean by "reverse the series," could you provide a longer example of what you want?

ecofin
Posts: 182
Joined: Fri May 10, 2013 11:24 am

Re: rename dummy and diagonal dummy

Postby ecofin » Sat Apr 08, 2017 2:47 am

Hello,

All previous programs generate dummy equal 1 and rename it by different way as required "d_{same date}" for each frequency ( day, month, week, interday, or by spanning by two month, two weeks...), how can generate and rename defferent trend "t_{same date}" "b_{same date}" in same time with the series dummy by the previous code (the same logic of previous programs) . below you find an example that what i need.
Attachments
dum 2 and trend 2.png
dum 2 and trend 2.png (9.81 KiB) Viewed 3735 times
dum and trend.png
dum and trend.png (9.71 KiB) Viewed 3735 times

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Mon Apr 10, 2017 9:00 am

Hello,

I see. You can generate both types of trends with fairly simple @recode statements. For example,

Code: Select all

series t_003 = @recode(d_003, @nan(t_003(-1), 0) + 1, 0)
series b_003 = @recode(d_003, 3, 0)

The same idea should work for both the cumulative and non-cumulative dummies (d1_* and d_*).

ecofin
Posts: 182
Joined: Fri May 10, 2013 11:24 am

Re: rename dummy and diagonal dummy

Postby ecofin » Mon Apr 10, 2017 9:30 am

Hello,

if i use the one of previous code (in page two) it doesn't work correctly, and i would to generate all the (d_, t_, b_, d1_, t1_, b1_) not one by one, and the " series {%series_name1} = @recode({%series_name}, @nan({%series_name}(-1), 0)+2 , 0)" generate this t_001= 1 2 2 00000, here i have just make your code for three spanning by week. have you understood me :roll:

!size = 3 'how many weeks per dummy
!first_date_number = @dateval(@otod(1))
for !i = 1 to @obsrange
!week = @datediff(@dateval(@otod(!i)), !first_date_number, "ww")
!id = @floor(!week / !size) + 1
%series_name = "d_" + @str(!id, "i03")
%series_name1 = "t_" + @str(!id, "i03")
%series_name2 = "b_" + @str(!id, "i03")
%series_name3 = "d1_" + @str(!id, "i03")
%series_name4 = "t1_" + @str(!id, "i03")
%series_name5 = "b1_" + @str(!id, "i03")
if not @isobject(%series_name) then
series {%series_name} = @floor(@datediff(@date, !first_date_number, "ww") / !size) + 1 = !id
series {%series_name1} = @recode({%series_name}, @nan({%series_name}(-1), 0)+1, 0)
series {%series_name2} =@recode({%series_name}, 3, 0)
'series {%series_name3}=?
'series {%series_name4}=?
'series {%series_name5}=?
endif
next

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Mon Apr 10, 2017 10:20 am

There are a few bugs. In the line generating series t_*, the series inside the @nan should be %series_name1 not %series_name (note that in my original example it's t_003, not d_003).

Code: Select all

series {%series_name1} = @recode({%series_name}, @nan({%series_name1}(-1), 0)+1, 0)

Generating series b_*, the constant 3 needs to be replaced with the unique identifier for the dummy.

Code: Select all

series {%series_name2} = @recode({%series_name}, !id, 0)

Generating the basic cumulative dummies, d1_*, is almost exactly he same the non-cumulative dummies, d_*, you just accept any identifier less than or equal to the current identifier ("=" becomes "<=").

Code: Select all

series {%series_name3} = @floor(@datediff(@date, !first_date_number, "ww") / !size) + 1 <= !id

ecofin
Posts: 182
Joined: Fri May 10, 2013 11:24 am

Re: rename dummy and diagonal dummy

Postby ecofin » Mon Apr 10, 2017 2:36 pm

Great, thank you for your help EViews Matt. 8)
Nice day.

clubmed
Posts: 81
Joined: Sun Nov 30, 2014 3:03 am

Re: rename dummy and diagonal dummy

Postby clubmed » Thu Apr 13, 2017 8:00 am

Hello,

I have make some modification to rename dummy series when i spanning by three weeks or by others frequency with two ways, but the two modification doesn't work:
1/rename dummy by the corresponding start date: d_2000_01_03_001, d_2000_01_24_002, d_2000_02_14_003,...etc (d_{start date}_001), but the series will be renamed by this: d_2000_01_03_001, d_2000_01_10_002, d_2000_02_17_003 with this code:
%series_name = "d_" +@datestr(@dateval(@otod(!id)), "YYYY_MM_DD_")+ @str(!id, "i03")

wfcreate w 03/01/2000 31/12/2001
!size = 3 'how many weeks per dummy
!first_date_number = @dateval(@otod(1))
for !i = 1 to @obsrange
!week = @datediff(@dateval(@otod(!i)), !first_date_number, "ww")
!id = @floor(!week / !size) + 1
%series_name = "d_" +@datestr(@dateval(@otod(!id)), "YYYY_MM_DD_")+ @str(!id, "i03")
if not @isobject(%series_name) then
series {%series_name} = @floor(@datediff(@date, !first_date_number, "ww") / !size) + 1 = !id
endif
next

2/rename dummy by the corresponding start date and end date: d000103_000117_001, d000124_000207_002,...etc (d{start date}_{end date}_001), but the series will be renamed by this d000103_000106_001, d000110_000113_002, ...etc with this code:
%series_name = "d" +@datestr(@dateval(@otod(!id)), "YYMMDD_")+@datestr(@dateval(@otod(!id))+3, "YYMMDD_")+ @str(!id, "i03") but it doesn't work.
how can rename dummy by start date, and by start date and end date, when i spanning by different frequency.

EViews Matt
EViews Developer
Posts: 431
Joined: Thu Apr 25, 2013 7:48 pm

Re: rename dummy and diagonal dummy

Postby EViews Matt » Thu Apr 13, 2017 9:03 am

Hello,

The solutions to both your questions are the same. At the moment, you're creating your series names by treating !id as an observation and using it in @otod(!id). But !id isn't an observation number, it's a function of the observation numbers that produces a unique value for each group of weeks (every three weeks in your example). More specifically, for the 105 observations in your example, !id ranges from 1 to 35, so @otos(!id) will produce the first 35 dates in your sample. However, you can calculate the observation number of the first week in each group from !id, it's just (!id - 1) * !size + 1. Use that as the argument to @otod. Similar, the observation number of the last week in each group is !id * !size, assuming that produces a valid observation number (since the last group may hold fewer than !size weeks).
Last edited by EViews Matt on Thu Apr 13, 2017 1:48 pm, edited 1 time in total.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 7 guests