Page 8 of 8

Re: An introduction to EViews programming.

Posted: Tue Jul 07, 2015 10:44 pm
by maujasmin
xxx

Re: An introduction to EViews programming.

Posted: Wed Jul 08, 2015 8:26 am
by EViews Gareth
You could use a for loop to loop through the variables. But if you've already written it out like that, it might be simpler to just leave it as is.

The wfopen command has a "range=" argument to specify the Excel range.

Re: An introduction to EViews programming.

Posted: Fri Jul 10, 2015 1:58 am
by maujasmin
How to use loop if I am going to use that for a series in a workfile?

Re: An introduction to EViews programming.

Posted: Wed Jul 22, 2015 10:05 am
by EViews Gareth
I have no idea what you're asking.

Re: An introduction to EViews programming.

Posted: Thu Apr 14, 2016 2:24 am
by Sammoland
Hi All

This post is in reference to an earlier post, but I wasn't sure how to reply to that.

I am trying to create a for loop that loops through a group of variables, and then runs an auto ARMA process through each individual equation. The auto ARMA is quite basic, and the loop begins to run, but after two variables it just keeps re-iterating and it will not solve.

Here is the for loop for referring to the group, where gexp is the name of the group:

Code: Select all

   pageselect experiment

   delete *

   smpl 1980m1 2016m12

   'read(b2, s=top_ten)  {%pathread}\correl_first.xls range=B2

   'wfopen {%pathread}\correl_first.xls range=B2

   import {%pathread}\correl_first.xls range=A2

   group gexp *

      for %zz resid c

      gexp.drop {%zz}

      next   

   'copy *

   for !j=1 to gexp.@count
      %var = gexp.@seriesname(!j)



Would this be a data issue? I tried removing the problematic variable but it still encounters the same issue. Here is the auto ARMA code, which follows straight after above:

Code: Select all

%eqname = "arma" 'name of equation object that will be used.
'%dep = "y1_ind" 'dependent variable

%maxAR = "5" 'maximum number of AR terms
%maxMA = "5" 'maximum number of MA terms

%regs = "C " 'independent variables
%criterion = "@schwarz" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for Hannan-Quinn

!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)

close {%eqname}

'create table for storing critical values.
%matname = "crits"
if @isobject(%matname) then
%matname = "__crits"
if @isobject(%matname) then
delete {%matname}
endif
endif
table(!maxar+2,!maxma+2) {%matname}
{%matname}(1,1) = "AR / MA"
{%matname}.setlines(1) +b
{%matname}.setlines(a) +r

'set sample
smpl @first+!maxAR @last

!mincrit = 1e12 'set the minimum to an artificially large value to begin

'estimate the models
%arstring = ""
for !i=0 to !maxar
'build up string for AR terms.
if !i>0 then
%arstring = %arstring + " ar(" + @str(!i) + ")"
endif
%mastring = ""
for !j=0 to !maxma
'build up string for MA terms
if !j>0 then
%mastring = %mastring + " ma(" + @str(!j) + ")"
endif
'estimate equation

smpl 1980m1 %end
equation {%eqname}.ls dlog({%var}) {%regs} {%arstring} {%mastring}

'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%eqname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%eqname}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%eqname}.@hq
endif
'compare criterion
if !crit < !mincrit then
!mincrit = !crit
!bestAR = !i
!bestMA = !j
%bestARstr = %arstring 'store the best ar string
%bestMAstr = %mastring 'store the best ma string
{%matname}.settextcolor(@all) black 'table formatting.
!ii=!i+2
!jj=!j+2
{%matname}.settextcolor(!ii,!jj) red
endif
{%matname}(!i+2,!j+2) = !crit
{%matname}(!i+2,1) = !i
{%matname}(1,!j+2) = !j
next
next

equation {%eqname}{%var}.ls dlog({%var}) {%regs} {%bestARstr} {%bestMAstr}

'show {%eqname}
'show {%matname}

smpl 2002m1 %forend
{%var} = @nan({%var},0)

smpl if {%var} = 0
{%eqname}.forecast {%var}_f
series MAPE_{%var} = @rmse({%var},{%var}_f)

smpl %beg %forend
'plot @pca({%var}_f) @pca({%var})

next

group g1_f *_f
group g1_mape mape_*

write {%pathwrite}\res_poolbrid_sam.xls g1 g1_f g1_mape


Thanks for your help!

Re: An introduction to EViews programming.

Posted: Mon May 02, 2016 4:25 am
by nemanja100
Dear friends, how to generate two series

Xt=2.2+0.6*Xt-1+0.3*Xt-2+e

Yt=0.5+0.3*Yt-1-0.6*Yt-2+e

where e is white noise, with using rndseed 3006?

Please help :)

Re: An introduction to EViews programming.

Posted: Mon May 02, 2016 6:12 am
by startz
What have you tried so far and where are you stuck?

Re: An introduction to EViews programming.

Posted: Wed Feb 07, 2018 11:01 am
by startz
You have two "for" statements and only one "next"

Re: An introduction to EViews programming.

Posted: Wed Feb 07, 2018 11:02 am
by Jara
Hi, I would like to run OLS for 63 time series variables based on 3 explanatory variables with lags depending on the best AIC.
I tried some of previous programs from this forum, but it does not work. It writes: For statement unterminated in "FOR !J=1 TO 4"

Code: Select all

!aic = 99999999
!maxlags = 4
!bestlag = 0
smpl @first+!maxlags @last

matrix(15,63) coefs

for !j=1 to !maxlags     
for !i=1 to 63

   equation eq{!i}.ls y{!i} c y{!i}(-1 to -!j) x(0 to -!j) z(0 to -!j)
   if eq.@aic < !aic then
      !bestlag = !j     'if this lag specification has the best AIC, then store this lag as !bestlag.
      !aic = eq{!i}.@aic
   endif

   colplace(coefs, eq{!i}.@coefs, !i)           'store coefficients into matrix
next


Thank you very much for you help. best regards, Jara

Re: An introduction to EViews programming.

Posted: Wed Feb 07, 2018 11:17 am
by EViews Gareth
You have two for statements but only one next statement. You need another one.

Re: An introduction to EViews programming.

Posted: Wed Feb 07, 2018 12:12 pm
by Jara
ups. thank you.
it works now, but it seems to me strange that all 63 regressions have full 4 lags for all explanatory variables ...

Code: Select all

!aic = 99999999
!maxlags = 4
!bestlag = 0
smpl @first+!maxlags @last

for !j=1 to !maxlags
for !i=1 to 63
   
equation eq{!i}.ls cz_{!i} c cz_{!i}(-1 to -!j) ugap(0 to -!j) fx(0 to -!j) vatup vatdown 
   if eq{!i}.@aic < !aic then
      !bestlag = !j     'if this lag specification has the best AIC, then store this lag as !bestlag.
      !aic = eq{!i}.@aic
   endif

next
next


and is there any easy way how to download the matrix with the p-values? I used to use

Code: Select all

matrix(17,63) coefs       '  at the beginning
colplace(coefs, eq{!i}.@coefs, !i)    ' at the FOR statement after the regression


thank you very much for your help.

Re: An introduction to EViews programming.

Posted: Wed Feb 07, 2018 2:04 pm
by EViews Gareth
use eq.@pvals rather than eq.@coefs

Re: An introduction to EViews programming.

Posted: Sat Apr 07, 2018 2:37 pm
by miharbi
Thnk you very much Gareth ..

Writing a text message to the output file

Posted: Sat May 19, 2018 9:18 am
by COM446
Hi

I want to write a text message to the output file :

output(t) c:\out.txt
text message
ls x1 c x2

Could you please help? I tried to use logmsg and logsave to the above output file. However, only regression result is written to the output file, but not the text message.

Thank you very much, Horward