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 » Fri Mar 31, 2017 12:17 pm

a) weeks start on a Monday witch 03/01/2000 was, for my first series.
weeks start on a Wednesday witch 05/01/2000 was, for my second series.
b) you make a great effort Mr Gareth i see, just it's help me for my study, i will referenced your program. could you help me :|

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

Re: rename dummy and diagonal dummy

Postby EViews Gareth » Fri Mar 31, 2017 1:58 pm

That still doesn't answer the question. How do you determine which month a week lies in?
Follow us on Twitter @IHSEViews

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

Re: rename dummy and diagonal dummy

Postby clubmed » Fri Mar 31, 2017 2:15 pm

if i understand by number (01 for 1st week, 02 second week,...etc)
d_2000_01_03_01 ( 01 first week of jan)
d_2000_01_10_02 ( 02 second week of jan)
d_2000_01_17_03
d_2000_01_24_04
d_2000_01_31_05

d_2000_02_07_01
d_2000_02_07_02
d_2000_02_07_03
d_2000_02_07_04...etc

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

Re: rename dummy and diagonal dummy

Postby clubmed » Sat Apr 01, 2017 3:21 pm

1/Do you mean the number of week in year. ( some year have 52 week and some year have 53 week)
the program doesn't create number zero at left, and generate

Code: Select all

create w 03/01/2000 28/12/2015
for !y=2000 to 2001
   %y = @str(!y)
   if !y<10 then
      %y = "0"+%y
   endif

           for !w=1 to 53
          %w=@str(!w)
          if !w<10 then
            %w="0"+%w
            endif

         series d_{%y}_{!w} = @recode(@year=!y and  @datepart(@date, "ww")=!w, 1, 0)
         
      next
   next

2/ for the interday i have the same problem.

Code: Select all

wfcreate 30min(Mon-Fri,8:00-9:00) 01/01/2000 31/12/2001

for !i=1 to 1563
%i = @str(!i)
    if %i<10 then
    %i="0"+%i
     endif
          if  %i>=10 and %i<100 then
           %i="0"+%i
     endif
if  %i>=100 and %i<1000 then
           %i="0"+%i
endif
series d_{!i}=@recode(@trend+1=!i,1,0)
next

3/ is there a way to put the date "@date" in the name of series d_{.._.._..} for any frequency (the date associated with a single observation dummy).

:cry:

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

Re: rename dummy and diagonal dummy

Postby EViews Gareth » Sun Apr 02, 2017 7:54 pm

I'm asking how you define which month a week is in.

If you assume that weeks start on a Sunday and the 31st of March is a Sunday, which month is that week in? March (where only the Sunday is actually in March) or April?

If the 31st March is a Wednesday, which month is that week in? March or April (half the week is actually in one month and half in the other).

Weeks don't line up with months. So you have to decide how you want to allocate them. Mathematically.

And of course you have to take into account that they will differ year to year. Week 5 may be in January one year and February the next.
Follow us on Twitter @IHSEViews

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

Re: rename dummy and diagonal dummy

Postby clubmed » Mon Apr 03, 2017 11:59 am

1/you are right, if i run the code below it generate all dummy, and i have generate three series:

series f1=@year
series f2=@month
series f3=@day

f1(1)=2000
f2(1)=1
f3(1)=3
how can rename all series dummy by each value in the series f1 f1 f3 like this: d_(f1(1))_(f2(1))_(f3(1))_001, d_(f1(2))_(f2(2))_(f3(2))_002....etc

wfcreate w 03/01/2000 31/12/2001
for !i=1 to @obsrange
%i=@str(!i)
if !i<10 then
%i="00"+%i
endif
if !i>=10 and !i<100 then
%i="0"+%i
endif
series d_{%i}=@recode(@trend+1=!i and @trend+1=!i,1,0)
next

2/ for the interday i have no solution.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Mon Apr 03, 2017 2:50 pm

Hello,

Given all the date irregularities, perhaps it would be simpler to build the dummy series' names as a custom date format, e.g.,

Code: Select all

for !i = 1 to @obsrange
   %tmp = @datestr(@dateval(@otod(!i)), "YYYY_MM_DD")
   series d_{%tmp} = @obsid = !i
next

The format string "YYYY_MM_DD" can be easily changed for any desired frequency.

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

Re: rename dummy and diagonal dummy

Postby clubmed » Tue Apr 04, 2017 4:56 am

1/ It's exactly that what i need thank you very much :D .
2/ I have made some modification in your code to generate dummy by every month but it gives me dummy with Sequentially of number.

create w 03/01/2000 31/12/2001
for !i = 1 to @obsrange
%tmp = @datestr(@dateval(@otod(!i)), "YYYY_MM")
series d_{%tmp} = @month
next

i need this:
Attachments
dummy_by_month.png
dummy by month
dummy_by_month.png (31.35 KiB) Viewed 9116 times

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Tue Apr 04, 2017 10:04 am

Ah, you also want dummies at a lower frequency than the data. Setting the dummy series to @month as you attempted to do will just fill them with month numbers, there's no comparison being performed. What you need is to compare each observation's year and month to the specification of each dummy. The following should work.

Code: Select all

%format = "YYYY_MM"
for !i = 1 to @obsrange
   %tmp = @datestr(@dateval(@otod(!i)), %format)
   if not @isobject("d_" + %tmp) then
      series d_{%tmp} = %tmp = @strdate(%format)
   endif
next

The format string defines the frequency of the dummy series, which can now be equal to or lower than the frequency of the data. I've included the if statement to avoid generating the same series multiple times, making the program more efficient. However, that means that any old dummy series need to be deleted before the program is run. You can always put "delete d_*" at the beginning of the program if need be.

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

Re: rename dummy and diagonal dummy

Postby clubmed » Tue Apr 04, 2017 3:24 pm

1/ if i understand if we change the first line by (%format = "YYYY_QQ") it gives me dummy with three month for every year at here it's clear for me, supose that i would like to generate dummy for every two month or by fourth month or by sixth month for every year, how can do this.
2/ i have no idea to modified your code to generate dummy for month and take the previous and so on, the problem with the code below that at (d_2001_01) it stat at first month (jan) in year 2001, how can take the year 2000 to considerate (all year 2000 take one). same for the others year 2002 2003...etc
i need this:
d_2000_01 =jan=1
d_2000_02 =from jan 2000 to feb 2000 =1
d_2000_03 =from jan 2000 to mar 2000 =1
...etc
d_2001_01 =from jan 2000 to jan 2001 =1
d_2001_02 =from jan 2000 to feb 2001 =1
....etc
d_2002_01 =from jan 2000 to jan 2002 =1
d_2002_02 =from jan 2000 to feb 2002 =1
....etc
create w 03/01/2000 31/12/2015
for !i=2000 to 2015
%i=@str(!i)

for !j=1 to 12
%j=@str(!j)
if !j<10 then
%j="0"+%j
endif

series d_{%i}_{%j}=@recode(@year=!i and @month<=!j,1,0)

next
next
group g d*

3/ it would be nice to have a function to colorate desired valuein the series or in the group (the value 1 for dummy). :)

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

Re: rename dummy and diagonal dummy

Postby clubmed » Wed Apr 05, 2017 8:45 am

clubmed wrote:1/ if i understand if we change the first line by (%format = "YYYY_QQ") it gives me dummy with three month for every year at here it's clear for me, supose that i would like to generate dummy for every two month or by fourth month or by sixth month for every year, how can do this.
2/ i have no idea to modified your code to generate dummy for month and take the previous and so on, the problem with the code below that at (d_2001_01) it stat at first month (jan) in year 2001, how can take the year 2000 to considerate (all year 2000 take one). same for the others year 2002 2003...etc
i need this:
d_2000_01 =jan=1
d_2000_02 =from jan 2000 to feb 2000 =1
d_2000_03 =from jan 2000 to mar 2000 =1
...etc
d_2001_01 =from jan 2000 to jan 2001 =1
d_2001_02 =from jan 2000 to feb 2001 =1
....etc
d_2002_01 =from jan 2000 to jan 2002 =1
d_2002_02 =from jan 2000 to feb 2002 =1
....etc
create w 03/01/2000 31/12/2015
for !i=2000 to 2015
%i=@str(!i)

for !j=1 to 12
%j=@str(!j)
if !j<10 then
%j="0"+%j
endif

series d_{%i}_{%j}=@recode(@year=!i and @month<=!j,1,0)

next
next
group g d*

3/ it would be nice to have a function to colorate desired valuein the series or in the group (the value 1 for dummy). :)

1/ i have made a modofication to your code with this:
by two month:
%format = "YYYY_MM"
for !i = 1 to @mod(@obsrange,2)
to gives me by two month ( or by 4 month by 6 month) and rename it d_{year}_{1st month}_{2nd month}_01, d_{year}_{3st month}_{4nd month}_02,...etc, it doesn't work.
by two week:
%format = "YYYY_MM_DD"
for !i = 1 to @mod(@obsrange,2)
and rename it d_{001}
it doesn't work. are there a solution to make dummy by two month or 4 month or 6 month, and by 2 week or 3 week or by 4 week or by 5 week.
i need this:
Attachments
by two week.png
by two week.png (31.51 KiB) Viewed 9038 times
by two month.png
by two month.png (34.08 KiB) Viewed 9038 times

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Wed Apr 05, 2017 10:13 am

The code I suggested exploits EViews' date format capabilities, and so is convenient only when the desired frequency maps easily to a date. It's not impossible to use other frequencies, e.g., every two months, but more extensive modifications to the code would be required. In such cases, you're probably better off using the nested loop strategy you began with. For example, dummies for two month periods:

Code: Select all

for !i = 2000 to 2015
   %year = @str(!i)
   for !j = 1 to 12 step 2
      %month1 = @str(!j, "i02")
      %month2 = @str(!j + 1, "i02")
      series d_{%year}_{%month1}_{%month2} = @year = !i and @month >= !j and @month <= !j + 1
   next
next

You can also the adapt the series generating expression for a cumulative effect, i.e., the dummy is true all the way back to the beginning of the sample. For example, you could change a single line above:

Code: Select all

      series d_{%year}_{%month1}_{%month2} = @before(%year + "m" + %month1) or (@year = !i and @month >= !j and @month <= !j + 1)

A two-, three-, etc., week dummies is a little trickier, since there isn't a @week function like there is for @year and @month, but @datepart and/or @datediff can be used instead.

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

Re: rename dummy and diagonal dummy

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

Works perfectly.
The series d_2000_001=@datepart(@date,"ww")<=2 it generate dummy for the 1st and 2nd week of month Jan for every year ( for the first and second week of Jan 2000 and the first and second week Jan 2001 ..etc in same series d_{2000}_{001}), and i don't know how to use the combination of the function @datepart and @datediff, could you solve this.

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

Re: rename dummy and diagonal dummy

Postby EViews Matt » Wed Apr 05, 2017 3:30 pm

It occurs to me you probably want the week dummies to cross year boundaries, e.g., for dummies spanning 5 weeks there will be a dummy covering part of 2000 and 2001 (weeks 51-55). It's probably easier to go back to an observation driven loop in that case, like the format string examples, but instead of using a format string use another identifier that is unique to each dummy (based on how many weeks have passed since the beginning of the sample). For example,

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, "ww")
   !id = @floor(!week / !size) + 1
   %series_name = "d_" + @str(!id, "i03")
   if not @isobject(%series_name) then
      series {%series_name} = @floor(@datediff(@date, !first_date_number, "ww") / !size) + 1 = !id
   endif
next

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

Re: rename dummy and diagonal dummy

Postby clubmed » Thu Apr 06, 2017 6:30 am

1/Thank you to make this possible, and thank you for all your effort.
2/just one question: i would like to generate a series frequency interday like this (1 2 3, 1 2 3,...etc) or (1 2 3 4, 1 2 3 4...etc),...etc, with this code: series tx = @recode(@day<>@day(-1), 1, tx(-1)+1) the three first observation take "NA" ( i know that a can fix it by Edit or by smpl). but if i have many "NA" obs it take long time to fix it by Edit. how can fix it by one way.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 25 guests