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

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

Re: rename dummy and diagonal dummy

Postby clubmed » Thu Apr 13, 2017 1:34 pm

Perfect, thanks!

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

Re: rename dummy and diagonal dummy

Postby clubmed » Tue Apr 18, 2017 4:00 pm

hello,

with this code it generate dummy just for the first week for every year, normally the function @seas detecte directly the frequency weekly.

Code: Select all

wfcreate w 3/01/2000 31/12/2001
for !i=1 to 5
%series_name = "d_" + @str(!i, "i02")
series {%series_name}=@seas(!i)
series d_last =(@seas(4) or @seas(5))
series d_first_last=(@seas(1) or @seas(4) or @seas(5))
series d_twoweek=(@seas(1) or @seas(2))
series d_threeweek=(@seas(1) or @seas(2) or @seas(4) or @seas(4))
next


1/i would like generate five series dummy:
d_001 for the first week for every month for each year
d_002 for the second week for every month for each year
....
d_005 for evey month contaned the 5th week for each year (because some month have five weeks)

2/ and generate different series dummy:
create d_last dummy for the last week for every month for each year
create d_first_last dummy for the first and last week for every month for each year
create d_twoweek dummy for the first and second week for every month for each year
create d_threeweek dummy for the two first and last week for every month for each year

3/it is possible to create a different sequence of dummy for each year in same series for example:
from 2000 2004: 10 value take 1 and 20 value take 0 and so on.
from 2005 2015: 15 value take 1 and 25 value take 0 and so on.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Wed Apr 19, 2017 1:24 pm

Hello,

I believe this thread contains the basic information you need for creating dummies based on week-in-month numbers.

Regarding (3), you can use samples to create different patterns in different sets of years. For example,

Code: Select all

smpl 2000 2004
scalar first_obs = @dtoo(@otods(1))
series x = @mod(@obsid - first_obs, 30) < 10
smpl 2005 2015
first_obs = @dtoo(@otods(1))
x = @mod(@obsid - first_obs, 40) < 15

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

Re: rename dummy and diagonal dummy

Postby clubmed » Thu Apr 20, 2017 7:41 am

Hello,

1/when i do this manually one by one it work, but when i use this code by loop i get error message.

Code: Select all

wfcreate w 3/01/2000 31/12/2001
for !i=2 to 5
for !j=1 to 35 step 7
%series_name = "d_" + @str(!i, "i02")
series d_01= @date < @datefloor(@date,"month") + 7
series {%series_name} = @date>=@datefloor(@date,"month") +!j and @date <@datefloor(@date,"month") + !j+7
next
next


(2) and (3) it worked perfectly. thank you so much.

4/i have not asking this question in my previous topic because i know that EViews 9 can support just 24 characters :oops: .EViews 10 beta can support 300 characters (longs object name).
i have make modification in the program to rename dummy by the corresponding start date and time when i spannig by day or hour or minute but i can not get the rename series.

%series_name = "d_" +@datestr(@dateval(@otod((!id - 1) * !size + 1)), "YYYY_MM_DD_HH_MI")+ @str(!id, "i03")
%series_name = "d_" +@datestr(@dateval(@otod((!id - 1) * !size + 1)), "YYYY_MM_DD_HH_MI")+@datestr(@dateval(@otod((!id - 1) * !size + 1))), "YYYY_MM_DD_HH_MI")+ @str(!id, "i03")

Code: Select all

wfcreate 30min(Mon-Fri,8:00-9:00) 03/01/2000 31/12/2001
!size =1 'how many weeks per dummy
!first_date_number = @dateval(@otod(1))
for !i = 1 to @obsrange
   !week = @datediff(@dateval(@otod(!i)), !first_date_number, "d")
   !id = @floor(!week / !size) + 1
  %series_name = "d" +@datestr(@dateval(@otod((!id - 1) * !size + 1)), "YYYY_MM_DD_HH_MI")+ @str(!id, "i03")
   if not @isobject(%series_name) then
      series {%series_name} = @floor(@datediff(@date, !first_date_number, "d") / !size) + 1 = !id
   endif
next

case 1:
rename dummy when spannig by one day with frequency interday:

d_{date sart}_{time sart}_0001
d_{date sart}_{time sart}_{time end}_0001

rename dummy when spannig by two day or three... with frequency interday:

d_{date sart}_{time sart}_{date end}_{time end}_0001

case2:
the problem when i would spanning by hour or minute or second when the day contain many time for example: 12 hour per day with 30 minute interval (3/01/2000 08:00,...3/01/2000 12:00, 4/01/2000 08:00,....4/01/2000 12:00....).
i would like create dummy (spannig by 1.5 hour or by two hour...) and rename it by:

d_{date sart}_{time sart}_0001
d_{date sart}_{time sart}_{date end}_{time end}_0001

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

Re: rename dummy and diagonal dummy

Postby clubmed » Mon Apr 24, 2017 12:17 pm

Hello,

1/what's wrong with my code to creating dummies based on week-in-month numbers.
4/When i use "(!id - 1) * !size + 1" to calculate the observation number of the first day in each group from !id, and "!id * !size" for the observation number of the last day in each group, it doesn't work. when i spanning by day with frequency interday, same when i spannig with every 120 minute...etc,
the problem when i would spanning by hour or minute or second when the day contain many time for example: 12 hour per day with 30 minute interval (3/01/2000 08:00,...3/01/2000 12:00, 4/01/2000 08:00,....4/01/2000 12:00....).
i would like create dummy (spannig by 1.5 hour or by two hour...) and rename it by:

d_{date sart}_{time sart}_0001
d_{date sart}_{time sart}_{date end}_{time end}_0001


any help would be appreciated.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Tue Apr 25, 2017 9:56 am

Hello,

1) When I run your code I don't receive any error messages, what are you receiving?

4) I think you're on the right track, but have gotten confused with the use of the !week variable. Remember, the idea was to map a high-frequency identifier to a low-frequency identifier (!id), which would then be used to define the dummies. If the low frequency is a nice integral multiple of the high frequency you can simplify some of the previous code. For example:

Code: Select all

' Example date structure, 12 hour days with half hour increments.
wfcreate 30min(Mon-Fri,6:00-18:00) 01/03/2000 12/31/2001

' We'll create dummies for every 2 hour period.
!size = 4 ' Every four observations go into one dummy.
for !i = 1 to @obsrange
   !id = @floor((!i - 1) / !size) + 1
   %series_name = "d_" + @datestr(@dateval(@otod((!id - 1) * !size + 1)), "YYYY_MM_DD_HH_MI_") + @datestr(@dateval(@otod(!id * !size)), "YYYY_MM_DD_HH_MI_") + @str(!id, "i04")
   if not @isobject(%series_name) then
      series {%series_name} = @floor(@trend / !size) + 1 = !id
   endif
next

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

Re: rename dummy and diagonal dummy

Postby clubmed » Tue Apr 25, 2017 4:22 pm

1/the problem with my code is: (d_02, d_03, d_04, d_05) generate just value 1 for the last month with day equal 30 for each years, you can see this. and can i intoduce d_01 in the loop.
2/the code (frequency interday) work perfectly thank you.
3/i have panel 576 obs (15 years monthly with series "id01" and alpha series "var01") 3 croos represent like this:
elc for aus, can, fra
hyd for aus, can, fra
fuel for aus, can, fra
the code below can create 192 dummies, but after d_65 to d_192 all equal zero (workfile below), how can make diagonal dummy (d_65 to d_192) for the "can" and "fra"


' We'll create dummies for every 2 hour period.
!size = 3 ' Every four observations go into one dummy.
for !i = 1 to @obsrange
!id = @floor((!i - 1) / !size) + 1
%series_name = "d_"+ @str(!id, "i03")
if not @isobject(%series_name) then
series {%series_name} = @floor(@trend / !size) + 1 = !id
endif
next

when i have identification series and alpha series (or crossid and dateid) how can rename 192 dummy by the corespending date(aus-98m01,....fra-98m01...) for example:
d_{var01}_{start date}_001
d_{var01}_{start date}_{end date}_001...

i have use %series_name = "d" + @datestr(@dateval(@otod((!id-1 ) * !size+1)), "YYYY_MM") + @str(!id, "i03") but doesn't work.

*)the code should be applicable for panel interday too.
Attachments
panel_2.wf1
(1003.3 KiB) Downloaded 235 times

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

Re: rename dummy and diagonal dummy

Postby clubmed » Wed Apr 26, 2017 2:14 pm

1/Probably i have not asking question in the good way,
how can rename dummy series by date series "id01" and cross section ID series "var01" when i use the code below i get error message:

Code: Select all

!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, "m")
   !id = @floor(!week / !size) + 1
   %series_name = "d" +"_AUS"+@datestr(@dateval(@otod(!(!id - 1) * !size + 1)), "YYYY_MM_")+ @str(!id, "i03")
   if not @isobject(%series_name) then
      series {%series_name} = @recode(@floor(@datediff(@date, !first_date_number, "m") / !size) + 1 = !id and var01="AUS" ,1,0)
   endif
next

i need this:
d_AUS_{start date}_001,...
d_AUS_{start date}_{end date}_001,...
but if i have panel with frequency interday the code above will be change to be compatible to rename series when i spannig with hour or minute.
have you understood me.
2/the problem with my code to creating dummies based on week-in-month numbers is: (d_02, d_03, d_04, d_05) generate just value 1 for the last month with day equal 30 for each years, you can see this. and can i intoduce d_01 in the loop.

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

Re: rename dummy and diagonal dummy

Postby clubmed » Thu Apr 27, 2017 9:56 am

Any idea to help me.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Fri Apr 28, 2017 9:15 am

Regarding your week-in-month dummies, you have the right idea for creating each dummy, but your looping is incorrect. You don't need two nested loops, that will go through every combination of !i and !j. Since you end up creating the same dummies multiple times, you'll only see the last version you create for the last value of !j, which is why d_02 through d_05 all contain the same data.

There's a simple mathematical relationship between each dummy's number, 1 through 5, and the constants that are added to @datefloor. If the dummy number is !i, then the smaller constant is 7 * (!i - 1) and the larger constant is 7 * !i. You can use this relationship to do everything within a single loop.

Code: Select all

for !i = 1 to 5
   series d_0!i = @date >= @datefloor(@date,"month") + 7 * (!i - 1) and @date < @datefloor(@date,"month") + 7 * !i
next

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

Re: rename dummy and diagonal dummy

Postby clubmed » Fri Apr 28, 2017 10:13 am

1/ There is no solution to rename dummy for panel. the problem it contain alphanumeric. (aus - 98M01)...
2/ This trick has escaped me, thanks!. :)

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

Re: rename dummy and diagonal dummy

Postby clubmed » Mon May 01, 2017 7:06 am

Any help would be appreciated.
Thank you in advance.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Mon May 01, 2017 9:27 am

Hello,

Regarding your panel data, if you open your workfile and issue the command "show @trend" you'll see why the last 2/3 of your dummies are all zeros. @trend resets to zero at the beginning of each cross-section, so it counts between 0 and 191 three times, not between 0 and 575 to match the loop. Also, because @trend repeats, for the first 1/3 of your dummies there will be three areas of each dummy that are ones. For example, if you look at d_001, AUS-98m1 through AUS-98m3 are ones (which is correct), but so are CAN-98m1 through CAN-98m3 and FRA-98m1 through FRA-98m3. The logic of the code assumed that @trend produces unique numbers for every observation, which is not true with panel data. However, if you look in the EViews documentation for panel data you'll see that the function @obsnum will produce a unique number for every observation. Try replacing @trend with (@obsnum - 1). @trend starts at 0 while @obsnum starts at 1, hence the subtraction.

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

Re: rename dummy and diagonal dummy

Postby clubmed » Mon May 01, 2017 10:21 am

Hello,
Great!, thank you so much for your reply, but i have ask you a question how to introduce identification "AUS", "CAN", "FRA" (d_AUS_...,...d_CAN..., d_FRA....), when is the alpha series "var01" or in other case crossid (1 1 1 1..., 2 2 2 2..., ....) (1-98m01, 1-98m02,...) d_{crossid}_..., it help to organize all series.
if i make this (identification and start date):
%series_name = "d_AUS"+@datestr(@dateval(@otod((!id - 1) * !size + 1)), "YYYY_MM_DD_")+ @str(!id, "i03") all series will be named by "AUS".
it is posibole to combine identification+date to rename the dummy series.
i would like to keep the code for intraday that will be pretty general when i spanning with any frequency and rename it by identification, and start date or end date or both.
Last edited by clubmed on Mon May 01, 2017 11:04 am, edited 1 time in total.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Mon May 01, 2017 10:36 am

You can use the values in your var01 series as part of the series name construction, for example,

Code: Select all

%series_name = "d_" + var01(!i) + "_" + ...


Return to “Data Manipulation”

Who is online

Users browsing this forum: Google [Bot] and 14 guests