Translating Eviews model into R





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I just started working with data analysis and I know basics R. My company used to run forecast models with Eviews and now they asked me to put it all on R so I can run the models as well (I do not have Eviews or know how to use it!). Can anyone please help me? I would also appreciate if you have any material on R to recommend.



The code gets a xls file with multiple variables. Then it runs lots of models with different combinations of those variable, and stores everything in a group (I displayed only the first models because there are more than 100!!). Last, it calculates the MAE and RMSE for each of the models.



Any help is welcome! Thank you very much



'##########################################################                 
'# Modelos para PIM
'##########################################################

'Defines working path
cd " "

' Limpa workfile anterior
close pim_linked.wf1
wfcreate(wf=pim_linked,page=origin) m 1991m01 2020m12
delete *

'Lê dados da pim.xls no worksheet origem
read(s=origem,b2) pim.xls 12

' Define tabela para armazenar resultados
table tab_mom
table tab_yoy

'Linha incrementa a cada modelo
!linha = 1

' Escolher x como o numero até o mês da ultima observação da PIM
!x = @dtoo("2018:06")

'Define ultima data da amostra
%data = @otod(!x)
%dataproj = @otod(!x + 1)



''''Geral
group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) dlog(energia) _
@seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
!linha = !linha + 1
group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) _
@seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
!linha = !linha + 1
group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) _
@seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)

!fim = !linha

For !i = 1 To !fim
smpl 2002m01 %data
equation eqt{!i}.ls(n) modelo_mom{!i}

smpl %dataproj %dataproj
eqt{!i}.forecast proj
y(!x + 1) = proj(!x + 1)

smpl 2002m1 %dataproj 'Amplia amostra para dessazonalizar
y.x12(mode=a,sfile="P:MacroX12omegav03allx12aPIMeviews.txt") 'Dessazonaliza série

tab_mom(!i,1) = proj(!x + 1) 'Armazena projeção para y(!x + 1) na primeira coluna
tab_mom(!i,2) = y_sa(!x + 1) 'Armazena proj y_sa(!x + 1)
tab_mom(!i,3) = eqt{!i}.@rbar2 'Armazena R^2 ajustado na terceira coluna
tab_mom(!i,4) = eqt{!i}.@aic
tab_mom(!i,5) = eqt{!i}.@schwarz
'tab_mom(!i,6) = eqt.@dw

'Forecast one month ahear, for 12 months
For !j = 1 To 12
series pim_frcst
%ultima_data = @otod(!x - !j)
%data_previsao = @otod(!x - !j + 1)
smpl 2002m01 %ultima_data
equation eqt_f.ls(n) modelo_mom{!i}

smpl %data_previsao %data_previsao
eqt_f.forecast pim_forecast
pim_frcst(!x - !j + 1) = pim_forecast(!x - !j + 1)
Next

smpl 2002m01 %data
genr pimF_errs = pim_frcst - y
genr pimF_errs_sqrt = pimF_errs^2
tab_mom(!i,6) = @sqrt(@mean(pimF_errs_sqrt))
tab_mom(!i,7) = @mean(abs(pimF_errs))
tab_mom(!i,8) = (y_sa(!x+1)/y_sa(!x) - 1)*100 'Armazena variação percentual com ajuste sazonal na quinta coluna


Next










share|improve this question































    0















    I just started working with data analysis and I know basics R. My company used to run forecast models with Eviews and now they asked me to put it all on R so I can run the models as well (I do not have Eviews or know how to use it!). Can anyone please help me? I would also appreciate if you have any material on R to recommend.



    The code gets a xls file with multiple variables. Then it runs lots of models with different combinations of those variable, and stores everything in a group (I displayed only the first models because there are more than 100!!). Last, it calculates the MAE and RMSE for each of the models.



    Any help is welcome! Thank you very much



    '##########################################################                 
    '# Modelos para PIM
    '##########################################################

    'Defines working path
    cd " "

    ' Limpa workfile anterior
    close pim_linked.wf1
    wfcreate(wf=pim_linked,page=origin) m 1991m01 2020m12
    delete *

    'Lê dados da pim.xls no worksheet origem
    read(s=origem,b2) pim.xls 12

    ' Define tabela para armazenar resultados
    table tab_mom
    table tab_yoy

    'Linha incrementa a cada modelo
    !linha = 1

    ' Escolher x como o numero até o mês da ultima observação da PIM
    !x = @dtoo("2018:06")

    'Define ultima data da amostra
    %data = @otod(!x)
    %dataproj = @otod(!x + 1)



    ''''Geral
    group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) dlog(energia) _
    @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
    !linha = !linha + 1
    group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) _
    @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
    !linha = !linha + 1
    group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) _
    @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)

    !fim = !linha

    For !i = 1 To !fim
    smpl 2002m01 %data
    equation eqt{!i}.ls(n) modelo_mom{!i}

    smpl %dataproj %dataproj
    eqt{!i}.forecast proj
    y(!x + 1) = proj(!x + 1)

    smpl 2002m1 %dataproj 'Amplia amostra para dessazonalizar
    y.x12(mode=a,sfile="P:MacroX12omegav03allx12aPIMeviews.txt") 'Dessazonaliza série

    tab_mom(!i,1) = proj(!x + 1) 'Armazena projeção para y(!x + 1) na primeira coluna
    tab_mom(!i,2) = y_sa(!x + 1) 'Armazena proj y_sa(!x + 1)
    tab_mom(!i,3) = eqt{!i}.@rbar2 'Armazena R^2 ajustado na terceira coluna
    tab_mom(!i,4) = eqt{!i}.@aic
    tab_mom(!i,5) = eqt{!i}.@schwarz
    'tab_mom(!i,6) = eqt.@dw

    'Forecast one month ahear, for 12 months
    For !j = 1 To 12
    series pim_frcst
    %ultima_data = @otod(!x - !j)
    %data_previsao = @otod(!x - !j + 1)
    smpl 2002m01 %ultima_data
    equation eqt_f.ls(n) modelo_mom{!i}

    smpl %data_previsao %data_previsao
    eqt_f.forecast pim_forecast
    pim_frcst(!x - !j + 1) = pim_forecast(!x - !j + 1)
    Next

    smpl 2002m01 %data
    genr pimF_errs = pim_frcst - y
    genr pimF_errs_sqrt = pimF_errs^2
    tab_mom(!i,6) = @sqrt(@mean(pimF_errs_sqrt))
    tab_mom(!i,7) = @mean(abs(pimF_errs))
    tab_mom(!i,8) = (y_sa(!x+1)/y_sa(!x) - 1)*100 'Armazena variação percentual com ajuste sazonal na quinta coluna


    Next










    share|improve this question



























      0












      0








      0








      I just started working with data analysis and I know basics R. My company used to run forecast models with Eviews and now they asked me to put it all on R so I can run the models as well (I do not have Eviews or know how to use it!). Can anyone please help me? I would also appreciate if you have any material on R to recommend.



      The code gets a xls file with multiple variables. Then it runs lots of models with different combinations of those variable, and stores everything in a group (I displayed only the first models because there are more than 100!!). Last, it calculates the MAE and RMSE for each of the models.



      Any help is welcome! Thank you very much



      '##########################################################                 
      '# Modelos para PIM
      '##########################################################

      'Defines working path
      cd " "

      ' Limpa workfile anterior
      close pim_linked.wf1
      wfcreate(wf=pim_linked,page=origin) m 1991m01 2020m12
      delete *

      'Lê dados da pim.xls no worksheet origem
      read(s=origem,b2) pim.xls 12

      ' Define tabela para armazenar resultados
      table tab_mom
      table tab_yoy

      'Linha incrementa a cada modelo
      !linha = 1

      ' Escolher x como o numero até o mês da ultima observação da PIM
      !x = @dtoo("2018:06")

      'Define ultima data da amostra
      %data = @otod(!x)
      %dataproj = @otod(!x + 1)



      ''''Geral
      group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) dlog(energia) _
      @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
      !linha = !linha + 1
      group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) _
      @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
      !linha = !linha + 1
      group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) _
      @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)

      !fim = !linha

      For !i = 1 To !fim
      smpl 2002m01 %data
      equation eqt{!i}.ls(n) modelo_mom{!i}

      smpl %dataproj %dataproj
      eqt{!i}.forecast proj
      y(!x + 1) = proj(!x + 1)

      smpl 2002m1 %dataproj 'Amplia amostra para dessazonalizar
      y.x12(mode=a,sfile="P:MacroX12omegav03allx12aPIMeviews.txt") 'Dessazonaliza série

      tab_mom(!i,1) = proj(!x + 1) 'Armazena projeção para y(!x + 1) na primeira coluna
      tab_mom(!i,2) = y_sa(!x + 1) 'Armazena proj y_sa(!x + 1)
      tab_mom(!i,3) = eqt{!i}.@rbar2 'Armazena R^2 ajustado na terceira coluna
      tab_mom(!i,4) = eqt{!i}.@aic
      tab_mom(!i,5) = eqt{!i}.@schwarz
      'tab_mom(!i,6) = eqt.@dw

      'Forecast one month ahear, for 12 months
      For !j = 1 To 12
      series pim_frcst
      %ultima_data = @otod(!x - !j)
      %data_previsao = @otod(!x - !j + 1)
      smpl 2002m01 %ultima_data
      equation eqt_f.ls(n) modelo_mom{!i}

      smpl %data_previsao %data_previsao
      eqt_f.forecast pim_forecast
      pim_frcst(!x - !j + 1) = pim_forecast(!x - !j + 1)
      Next

      smpl 2002m01 %data
      genr pimF_errs = pim_frcst - y
      genr pimF_errs_sqrt = pimF_errs^2
      tab_mom(!i,6) = @sqrt(@mean(pimF_errs_sqrt))
      tab_mom(!i,7) = @mean(abs(pimF_errs))
      tab_mom(!i,8) = (y_sa(!x+1)/y_sa(!x) - 1)*100 'Armazena variação percentual com ajuste sazonal na quinta coluna


      Next










      share|improve this question
















      I just started working with data analysis and I know basics R. My company used to run forecast models with Eviews and now they asked me to put it all on R so I can run the models as well (I do not have Eviews or know how to use it!). Can anyone please help me? I would also appreciate if you have any material on R to recommend.



      The code gets a xls file with multiple variables. Then it runs lots of models with different combinations of those variable, and stores everything in a group (I displayed only the first models because there are more than 100!!). Last, it calculates the MAE and RMSE for each of the models.



      Any help is welcome! Thank you very much



      '##########################################################                 
      '# Modelos para PIM
      '##########################################################

      'Defines working path
      cd " "

      ' Limpa workfile anterior
      close pim_linked.wf1
      wfcreate(wf=pim_linked,page=origin) m 1991m01 2020m12
      delete *

      'Lê dados da pim.xls no worksheet origem
      read(s=origem,b2) pim.xls 12

      ' Define tabela para armazenar resultados
      table tab_mom
      table tab_yoy

      'Linha incrementa a cada modelo
      !linha = 1

      ' Escolher x como o numero até o mês da ultima observação da PIM
      !x = @dtoo("2018:06")

      'Define ultima data da amostra
      %data = @otod(!x)
      %dataproj = @otod(!x + 1)



      ''''Geral
      group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) dlog(energia) _
      @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
      !linha = !linha + 1
      group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) dlog(nuci) _
      @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)
      !linha = !linha + 1
      group modelo_mom{!linha} dlog(y) c dlog(y(-1)) dlog(abcr) dlog(abcr(-1)) dlog(pmi) dlog(pmi(-1)) dlog(aco) dlog(papond) dlog(anf) dlog(ici) _
      @seas(1) @seas(2) @seas(3) @seas(4) @seas(5) @seas(6) @seas(7) @seas(8) @seas(9) @seas(10) @seas(11)

      !fim = !linha

      For !i = 1 To !fim
      smpl 2002m01 %data
      equation eqt{!i}.ls(n) modelo_mom{!i}

      smpl %dataproj %dataproj
      eqt{!i}.forecast proj
      y(!x + 1) = proj(!x + 1)

      smpl 2002m1 %dataproj 'Amplia amostra para dessazonalizar
      y.x12(mode=a,sfile="P:MacroX12omegav03allx12aPIMeviews.txt") 'Dessazonaliza série

      tab_mom(!i,1) = proj(!x + 1) 'Armazena projeção para y(!x + 1) na primeira coluna
      tab_mom(!i,2) = y_sa(!x + 1) 'Armazena proj y_sa(!x + 1)
      tab_mom(!i,3) = eqt{!i}.@rbar2 'Armazena R^2 ajustado na terceira coluna
      tab_mom(!i,4) = eqt{!i}.@aic
      tab_mom(!i,5) = eqt{!i}.@schwarz
      'tab_mom(!i,6) = eqt.@dw

      'Forecast one month ahear, for 12 months
      For !j = 1 To 12
      series pim_frcst
      %ultima_data = @otod(!x - !j)
      %data_previsao = @otod(!x - !j + 1)
      smpl 2002m01 %ultima_data
      equation eqt_f.ls(n) modelo_mom{!i}

      smpl %data_previsao %data_previsao
      eqt_f.forecast pim_forecast
      pim_frcst(!x - !j + 1) = pim_forecast(!x - !j + 1)
      Next

      smpl 2002m01 %data
      genr pimF_errs = pim_frcst - y
      genr pimF_errs_sqrt = pimF_errs^2
      tab_mom(!i,6) = @sqrt(@mean(pimF_errs_sqrt))
      tab_mom(!i,7) = @mean(abs(pimF_errs))
      tab_mom(!i,8) = (y_sa(!x+1)/y_sa(!x) - 1)*100 'Armazena variação percentual com ajuste sazonal na quinta coluna


      Next







      r forecasting eviews






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 22:57







      Amanda Restom de Castro

















      asked Nov 22 '18 at 21:49









      Amanda Restom de CastroAmanda Restom de Castro

      184




      184
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438348%2ftranslating-eviews-model-into-r%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438348%2ftranslating-eviews-model-into-r%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?