Page 1 of 2
loop with @daycount
Posted: Mon May 01, 2017 7:23 am
by ch2324
Hi for all,
I have three problem with my three parts of program
a) when i use the command manually series d01=@daycount("1"), ..., series d07=@daycount("7") it work but by loop it doesn't work i receive an error message. for the second part i would like to make x01=d01-d07, x02=d02-d07,....,x06=d06-d07.
Code: Select all
'part 01
for !i=1 to 7
series d0{!i}=@daycount("!i")
next
'part 02
series x07=@daycount
for !j=1 to 6
series x{0!j}=d0{!i}-d07
next
b) when i use series d_01=@daycount("1 5"),.., d_01=@daycount("3 7") it work but by loop it doesn't work.
Code: Select all
'part 03
for !m=1 to 3
for !n=5 to 7
series d0{!m}=@daycount("!m !n")
next
next
could you help me please, any help would be grateful.
Kind regards.
Re: loop with @daycount
Posted: Mon May 01, 2017 8:58 am
by EViews Mirza
The function @daycount("weekday range") takes on a string argument. Thus, your loops will never work because you're feeding a numeric value where a string should hold. Here's the code you're looking for:
Code: Select all
for !i=1 to 5
series d0!m=@daycount(@str(!i))
next
Re: loop with @daycount
Posted: Mon May 01, 2017 11:47 am
by ch2324
Hi,
Thank you for your response. :D
1/i get error message when i run the program. " D08 is not defined in "SERIES X0!J=D08-D07"." but i have not generate d08.
Code: Select all
' part 1 trade
for !i=1 to 7
series d0!i=@daycount(@str(!i))
next
group g1 d*
equation eq_trade.ls y c g1
'part 2 model01
series x07=@daycount
for !j=1 to 6
series x0!j=d0!i-d07
next
group g2 x*
equation eq_model01a.ls y c g2
'make two goups containning: first diff, first diff+seas diff
group dg2
group dsg2
for !k=1 to g2.@count
dg2.add d(g2(!k))
dsg2.add d(g2(!k),1,12)
next
' part 3
for !m=1 to 3
for !n=5 to 7
series d0{!m}=@daycount(@str(!m) @str(!n))
next
next
'part 4 model01 regular diff
equation eq_model01d.ls d(y) dg2
'part 5 model02 with regular and seasonal diff
equation eq_model02ds.ls d(y,1,12) dsg2
' part 6 model03: ma(1)
equation eq_model03dsma.ls d(y,1,12) dsg2 ma(1)
' part 7 model04: ma(1) and sma(12)
equation eq_model03dsmas.ls d(y,1,12) dsg2 ma(1) sma(12)
' part 8 final model
equation eq_model05dsmas.ls d(y,1,12) dsg2 ar( 1 to 2) ma(1) sma(12)
2/i get error message when i run the part 3 this " D01=@DAYCOUNT(@STR(1) @S is an illegal or reserved name in "SERIES D0{!M}=@DAYCOUNT(@STR(1) @STR(5))"."
Code: Select all
'part 03
for !m=1 to 3
for !n=5 to 7
series d0{!m}=@daycount(@str(!m) @str(!n))
next
next
Re: loop with @daycount
Posted: Mon May 01, 2017 1:10 pm
by EViews Matt
In (1), inside the second for loop you've used !i instead of !j.
In (2), you need to concatenate strings together with the + operator. @str(!m) @str(!n) should be @str(!m) + " " + @str(!n), since you need a space between the two numbers.
Re: loop with @daycount
Posted: Mon May 01, 2017 2:15 pm
by ch2324
it works 100%. :) :D
thanks you so much EViews Matt & EViews Mirza.
a last question: how can genarate series contained number of weeks in month or in quarterly?
Re: loop with @daycount
Posted: Mon May 01, 2017 2:29 pm
by startz
How would you define the number of weeks in a month? How many weeks were there in April 2017, for example?
Re: loop with @daycount
Posted: Tue May 02, 2017 8:50 am
by ch2324
Hi,
I see what do you mean Mr startz. Got it!
Re: loop with @daycount
Posted: Wed May 03, 2017 8:38 am
by ch2324
i would like to loop with three different ways by @daycount:
1)the loop below generate 49 series, i would like to generate just 7 series d_mon_01,...,d_sun_07.
Code: Select all
wfcreate m 1976m01 1990m12
for %d Mon Tue Wed Thu Fri Sat Sun
for !i=1 to 7
series d_{%d}_0!i=@daycount(@str(!i))
next
next
2)manually it work d_mon=@daycount("mon"),..., but with loop i get error message.
Code: Select all
wfcreate m 1976m01 1990m12
for %d Mon Tue Wed Thu Fri Sat Sun
series d_{%d}=@daycount(@str(%d))
next
3)when i make this manually it work series d_mon_thu=@daycount("mon thu"), but with loop i get error message:
Code: Select all
wfcreate m 1976m01 1990m12
for %m Mon Tue Wed
for %n Thu Fri Sat
for !i=1 to 3
series d_{%m}_{%n}_0!i=@daycount(@str(%m) + " " + @str(%n))
next
next
next
4) could i make two series (frequency monthly) contained the number of weeks and fortnight?
Re: loop with @daycount
Posted: Wed May 03, 2017 8:53 am
by EViews Mirza
Again, you are confusing string variables and numeric values. @daycount takes on a string argument. However, this time, your loop is running through %d which are already in string format. You cannot use @str(%d) @str() converts numeric values to strings, but %d is already a string. Secondly, to get your naming right, you have 49 series because you are creating a nested loop each with 7 iterations. Thus, 7x7=49. That's clearly not what you want. What you want is to have an additional index that updates by 1 every time you switch to a new loop iteration in %d. Thus, you initialize this index at 0 and then you update it every time the loop repeats. So, the code you are looking for is this.
Code: Select all
wfcreate m 1976m01 1990m12
!i=0
for %d Mon Tue Wed Thu Fri Sat Sun
!i=!i+1
series d_{%d}_0!i=@daycount(%d)
next
Re: loop with @daycount
Posted: Wed May 03, 2017 11:07 am
by ch2324
Thank you EViews Mirza.
1/the code below it work but it generate 9 series just i need this: d_mon_thu_01, d_thu_fri_02, d_wed_sat_03
wfcreate m 1976m01 1990m12
!i=0
for %m Mon Tue Wed
for %n Thu Fri Sat
!i=!i+1
series d_{%m}_{%n}_0!i=@daycount((%m)+" "+ (%n))
next
next
2/ and for my question about weeks and forthnight?
Re: loop with @daycount
Posted: Thu May 04, 2017 8:46 am
by EViews Matt
You don't want to use nested loops because you don't want every combination of your inner and outer loop values. However, EViews' for loops can iteration through several values at the same time:
Code: Select all
wfcreate m 1976m01 1990m12
!i=0
for %m %n Mon Thu Tue Fri Wed Sat
!i=!i+1
series d_{%m}_{%n}_0!i=@daycount((%m)+" "+ (%n))
next
Re: loop with @daycount
Posted: Thu May 04, 2017 10:47 am
by ch2324
Sorry i haven't seen your reply. thank you.
how can loop like this: d_Mon_Thu_01, d_Thu_Tue_02, d_Tue_Fri_03, d_Fri_Wed_04, d_Wed_Sat_05.
Re: loop with @daycount
Posted: Thu May 04, 2017 10:58 am
by EViews Matt
The quick-and-dirty way would be to change the list of days in the for loop, e.g., Mon Thu Thu Tue Tue Fri ...
Something more principled might be:
Code: Select all
wfcreate m 1976m01 1990m12
%days = "Mon Thu Tue Fri Wed Sat"
for !i = 1 to 5
%m = @word(%days, !i)
%n = @word(%days, !i + 1)
series d_{%m}_{%n}_0!i = @daycount(%m + " " + %n)
next
Re: loop with @daycount
Posted: Thu May 04, 2017 2:15 pm
by ch2324
I understand, thank you so much.
for my question about weeks and fortnight, there is no solution.
how can transfer the every last obs of week in month and date corresponding in the month from page freq weekly to the page monthly freq.
series date_lastw, series obs_lastw
Re: loop with @daycount
Posted: Sat May 06, 2017 7:10 am
by ch2324
How can import the date and the value corresponding from my page weekly to my page monthly?
e.g. the date of the last week for every month and his value.
same for the fortnight frequency.
any help would be gratefully appreciated.