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
::install_github('sagirumati/EviewsR') devtools
To run the package successfully, you need to rename the Eviews
executable to eviews
and then add the EViews installation
folder to path. Alternatively, you can use set_eviews_path
function to set the EViews path as follows:
set_eviews_path("C:/Program Files (x86)/EViews 10/EViews10.exe")
Please load the EviewsR package as follows:
```{r} .
library(EviewsR)
```
An Eviews workfile can be created using eviews_wfcreate
function in R.
eviews_wfcreate(wf="EviewsR_workfile",page="EviewsR_page",frequency = "m",start_date = "1990",end_date = "2022")
A chunk for Eviews can be created by supplying eviews
as
the engine name as shown below:
```{eviews EviewsR,eval=T,echo=T}
'This program is created in R Markdown with the help of EviewsR package
%path=@runpath
cd %path
wfcreate(page=EviewsR_page,wf=EviewsR_workfile) m 2000 2022
for %y EviewsR package page1 page2
pagecreate(page={%y}) EviewsR m 2000 2022
next
pageselect EviewsR_page
rndseed 123456
genr y=rnd
genr x=rnd
equation ols.ls y c x
freeze(EviewsROLS,mode=overwrite) ols
freeze(EviewsR_Plot,mode=overwrite) y.line
wfsave EviewsR_workfile
```
The \(R^2\) of the OLS equation is .
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
in the current directory.
A set of Eviews commands can be executed with the help of
exec_commands
function in R. The above Eviews chunk can be
translated using this function.
exec_commands(c('%path=@runpath','cd %path',
'wfcreate(page=EviewsR_page,wf=EviewsR_workfile) m 2000 2022',
'for %y EviewsR package page1 page2',
'pagecreate(page={%y}) EviewsR m 2000 2022',
'next',
' pageselect EviewsR_page',
'rndseed 123456',
' genr y=rnd',
'genr x=rnd',
'equation ols.ls y c x',
'freeze(EviewsROLS,mode=overwrite) ols',
'freeze(EviewsR_Plot,mode=overwrite) y.line',
'wfsave EviewsR_workfile',
'exit'))
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)
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)")
Eviews tables can be imported as kable
object by
import_table
function. Therefore, we can include the
results of the OLS generated by the Eviews chunk using the following R
chunk;
For the OLS result only:
options(knitr.kable.NA = '')
import_table(wf="EViewsR_workfile",page="EviewsR_page",table_name = "EViewsrOLS",table_range = "r7c1:r10c5",digits=3)
An EViews workfile can be saved various output formats using
eviews_wfsave
in function in R.
eviews_wfsave(wf="eviewsr_workfile",source_description = "EviewsR_wfsave.csv")
Similar to Eviews workfile, an Eviews page can be saved in various
formats by eviews_pagesave
function.
eviews_pagesave(wf="eviewsr_workfile",source_description = "EviewsR_pagesave.csv",drop_list = "y")
Data can be imported from external sources by
eviews_import
function.
eviews_import(wf="eviewsr_workfile",source_description = "EviewsR_pagesave.csv")
Use import
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$object_name
.
import(object_name = "import",wf="eviewsr_workfile",keep_list = c("x","y"))
plot(eviews$import$y,type="l",ylab="EviewsR",col="red")
Use export
function to export dataframe object to
Eviews.
export(wf="eviewr_export",source_description=eviews$import,start_date = '1990',frequency = "m")
EViews graph can be included in R Markdown by
eviews_graph
function.
=runif(100)
y=runif(100)
x=data.frame(x,y)
uu
eviews_graph(wf="EviewsR_workfile",page = "EviewsR_page",series="x y",mode = "overwrite",options = "m",merge_graphs =F,start_date="1",frequency="5",save_path = '')