knitr::opts_chunk$set( collapse = TRUE, comment = "#>", echo = T, eval=T, out.width = "45%", out.height = "20%", fig.show="hold", fig.align = "center", tidy = TRUE, tidy.opts = list(blank = FALSE, width.cutoff = 60) ) library(EviewsR) # set_eviews_path('EViews12_X64') library(knitr) library(ggplot2)
EviewsR is an R package that can run Eviews program from R. It also adds eviews
as knit-engine to knitr
package.
EviewsR can be installed using the following commands in R.
install.packages("EviewsR") OR devtools::install_github('sagirumati/EviewsR')
To run the package successfully, you need to do one of the following
Don't do anything if the name of EViews executable is one of the following: EViews13_x64
, EViews13_x86
,EViews12_x64
, EViews12_x86
, EViews11_x64
, EViews11_x86
,EViews10_x64
, EViews10_x86
,EViews9_x64
, EViews9_x86
, EViews10
. The package will find the executable automatically.
Rename the Eviews executable to eviews
or one of the names above.
Alternatively, you can use set_eviews_path
function to set the path the EViews executable as follows:
set_eviews_path("C:/Program Files (x86)/EViews 10/EViews10.exe")
Please load the EviewsR package as follows:
```r . library(EviewsR) ```
The package can work with base R, R Markdown or Quarto document.
After loading the package, a chunk for Eviews can be created by supplying eviews
as the engine name in R Markdown or Quarto document as shown below :
```{eviews} `r ''` #| label: fig-EviewsR #| eval: true #| fig.subcap: ["X graph","Y graph"] #| fig.cap: "EViews graphs imported automatically by fig-EviewsR chunk" 'This program is created in R Markdown with the help of EviewsR package wfcreate(page=EviewsRPage,wf=EviewsR_workfile) m 2000 2022 for %y EviewsR package page1 page2 pagecreate(page={%y}) EviewsR m 2000 2022 next pageselect EviewsRPage rndseed 123456 genr y=@cumsum(nrnd) genr x=@cumsum(nrnd) equation ols.ls y c x freeze(OLSTable,mode=overwrite) ols freeze(EviewsR_Plot,mode=overwrite) y.line wfsave EviewsR_workfile ```
#| label: fig-EviewsR #| eval: true #| fig.subcap: ["X graph","Y graph"] #| fig.cap: "EViews graphs imported automatically by fig-EviewsR chunk" #| echo: false 'This program is created in R Markdown with the help of EviewsR package wfcreate(page=EviewsRPage,wf=EviewsR_workfile) m 2000 2022 for %y EviewsR package page1 page2 pagecreate(page={%y}) EviewsR m 2000 2022 next pageselect EviewsRPage rndseed 123456 genr y=@cumsum(nrnd) genr x=@cumsum(nrnd) equation ols.ls y c x freeze(OLSTable,mode=overwrite) ols freeze(yy,mode=overwrite) y.line freeze(xx,mode=overwrite) x.line wfsave EviewsR_workfile
The above chunk creates an Eviews program with the chunk's content, then automatically open Eviews and run the program, which will create an Eviews workfile with pages containing monthly sample from 2000 to 2022. The program will also save an EViews workfile named EviewsR_workfile
in the current directory.
The eviews
chunk automatically returns the outputs of each equation object as a dataframe, accessible via chunkLabel$pageName_equationName
. For example, The $R^2$ of the ols
equation object is r EviewsR$eviewsrpage_ols$r2
, which can be accessed using `r knitr::inline_expr('EviewsR$eviewsrpage_ols$r2')`
. We can obtain the table object by chunkLabel$pageName_tableName
. Therefore, EviewsR$eviewsrpage_olstable
will give us the OLSTable
object as dataframe. Note the underscore (_
) between the pageName
and equationName
, and between the pageName
and tableName
.
EviewsR$eviewsrpage_ols$r2 EviewsR$eviewsrpage_ols$aic K=EviewsR$eviewsrpage_olstable[c(6,8,9),1:5] colnames(K)=NULL knitr::kable(K,row.names = F,caption = 'Selected cells of EViews table object')
The EViews series objects are also imported automatically as dataframe (by default) or xts
objects (if we use chunk option class="xts"
). They are accessed via chunkLabel$pageName
.
EviewsR$eviewsrpage |> head()
The function create_object()
can be used to create an Eviews object in the existing EViews workfile.
create_object(wf="EviewsR_workfile",action="equation",action_opt="",object_name="eviews_equation",view_or_proc="ls",options_list="",arg_list="y ar(1)")
create_object(wf="EviewsR_workfile",object_name="x1", object_type="series",expression="y^2")
EViews graphs can be included in R Markdown or Quarto document by eviews_graph()
function.
To create graph from existing EViews series objects:
#| label: fig-eviewsGraph #| fig.cap: Graphs of existing EViews series objects imported by fig-eviewsGraph chunk #| out.width: 45% #| out.height: 30% eviews_graph(wf="EviewsR_workfile",page = "EviewsRPage",series="x y",mode = "overwrite", graph_options = "m")
We can also create objects from an R dataframe
#| label: fig-eviewsGraph1 #| fig.cap: Graphs of an R dataframe imported by fig-eviewsGraph1 chunk #| out.width: 90% #| out.height: 70% Data=data.frame(x=cumsum(rnorm(100)),y=cumsum(rnorm(100))) eviews_graph(series=Data,group=TRUE,start_date="1990Q4",frequency="Q")
Data can be imported from external sources by eviews_import()
function.
write.csv(Data,"eviews_import.csv",row.names = FALSE)
eviews_import(source_description = "eviews_import.csv",start_date = "1990",frequency = "m", rename_string = "x ab",smpl_string = "1990m10 1992m10")
Alternatively, use the dataframe as the source_description
.
eviews_import(source_description = Data,wf="eviews_import1",start_date = "1990", frequency = "m",rename_string = "x ab",smpl_string = "1990m10 1992m10")
Similar to Eviews workfile, an Eviews page can be saved in various formats by eviews_pagesave()
function.
eviews_pagesave(wf="eviewsr_workfile",page="EviewsRPage",source_description = "pagesave.csv",drop_list = "y")
An Eviews workfile can be created using eviews_wfcreate()
function in R.
eviews_wfcreate(wf="eviews_wfcreate",page="EviewsRPage",frequency = "m", start_date = "1990",end_date = "2022")
Create a workfile from a dataframe
eviews_wfcreate(source_description=Data,wf="eviews_wfcreate1",page="EviewsR_page",frequency="m", start_date="1990")
An EViews workfile can be saved various output formats using eviews_wfsave()
in function in R.
eviews_wfsave(wf="eviewsr_workfile",source_description = "wfsave.csv")
A set of Eviews commands can be executed with the help of exec_commands()
function in R.
exec_commands(c("wfcreate(wf=exec_commands,page=eviewsPage) m 2000 2022"))
eviewsCommands=r'(pagecreate(page=eviewspage1) 7 2020 2022 for %page eviewspage eviewspage1 pageselect {%page} genr y=@cumsum(nrnd) genr x=@cumsum(nrnd) equation ols.ls y c x graph x_graph.line x graph y_graph.area y freeze(OLSTable,mode=overwrite) ols next )' exec_commands(commands=eviewsCommands,wf="exec_commands")
Use export_dataframe()
function to export dataframe object to Eviews.
export_dataframe(wf="export_dataframe",source_description=Data,start_date = '1990',frequency = "m")
Import EViews equation data members into R, R Markdown or Quarto.
import_equation(wf="EviewsR_workfile",page="EviewsRPage",equation="OLS")
To access the imported equation in base R:
eviews$eviewspage_ols
Import EViews graph objects(s) into R, R Markdown or Quarto.
#| label: fig-importGraph #| fig.cap: EViews graphs imported using import\_graph() function import_graph(wf="eviewsr_workfile")
To import only graphs that begin with x:
#| label: fig-importGraph1 #| fig.cap: EViews graphs that begin with X imported using import\_graph() function import_graph(wf="exec_commands",graph="x*")
Eviews tables can be imported as kable
object by import_kable()
function. Therefore, we can include the
import_kable(wf="EViewsR_workfile",page="EviewsRPage",table = "OLSTable", caption = "Selected cells of EViews table imported using import\\_kable() function", range = "r7c1:r10c5",digits=3)
Use import_series()
function to import data from EViews to R as a dataframe. The function creates a new environment eviews
, whose objects can be accessed via eviews$pageName
.
import_series(wf="eviewsr_workfile")
To access the series in base R:
eviews$eviewspage |> head()
To import the series as an xts
object:
import_series(wf="eviewsr_workfile",series = c("x","y"),class='xts')
Import EViews table objects(s) into R, R Markdown or Quarto.
To import all table objects across all pages
import_table(wf="EviewsR_workfile")
To import specific table objects, for example OLSTable
import_table(wf="EviewsR_workfile",table="OLStable")
To import table objects on specific pages
import_table(wf="EviewsR_workfile",page=" EviewsRPage")
To access the table in base R (eviews$pageName_tableName
)
eviews$eviewspage_olstable
Import EViews equation data members, graph, series and table objects(s) into R, R Markdown or Quarto. This function is a blend of import_equation()
, import_graph()
, import_series()
and import_table()
functions.
To import all equation, graph, series and table objects across all pages
#| label: fig-importWorkfile #| fig.cap: EViews graphs automatically imported by import\_workfile() function import_workfile(wf="EviewsR_workfile")
To import specific objects
import_workfile(wf="exec_commands",equation="ols",graph="x*",series="y*",table="ols*")
To import objects on specific page(s)
import_workfile(wf="exec_commands",page="eviewspage eviewspage1")
To access the objects in base R:
eviews$eviewspage_ols # equation # eviewspage-x_graph # graph saved in "figure/" folder eviews$eviewspage |> head() # series eviews$eviewspage_olstable # table
A set of random walk series can be simulated in R using EViews engine, thanks to rwalk()
function.
rwalk(wf="eviewsr_workfile",series="X Y Z",page="",rndseed=12345,frequency="M",num_observations=100,class='xts')
#| label: fig-rwalk #| fig.cap: Plots of imported EViews random walk series objects #| dpi: 300 #| out.width: 45% #| fig.dim: [7,4] xts::plot.xts(rwalk$xyz,type="l",main = "") ggplot2::autoplot(rwalk$xyz,facet='')
The demo files are included and can be accessed via demo(package="EviewsR")
demo(create_object()) demo(eviews_graph()) demo(eviews_import()) demo(eviews_pagesave()) demo(eviews_wfcreate()) demo(eviews_wfsave()) demo(exec_commands()) demo(export_dataframe()) demo(import_equation()) demo(import_graph()) demo(import_kable()) demo(import_series()) demo(import_table()) demo(import_workfile()) demo(rwalk()) demo(set_eviews_path())
Template for R Markdown is created. Go to file->New File->R Markdown-> From Template->EviewsR
.
Please download the example files from Github.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.