R and Eviews: using xget

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Gareth, EViews Moderator

Zeno
Posts: 11
Joined: Thu Jan 08, 2009 9:47 am

R and Eviews: using xget

Postby Zeno » Fri Jul 23, 2010 8:46 am

using EViews 7.1

I would like to access R for a certain bootstrap procedure and I am using the new EViews to R interface. I have problems finding books on this topic or documents on the internet. In particular, I cannot figure out how to get a matrix from R back into EViews using the xget command. Although xget(name = var1, type = vector) works fine, a similar version using xget(name = var1, var2 , type = matrix) does not work. It appears that I have a syntax error in the names argument.

Here is an example code:


!n = 1000
xopen(type=r, case=lower)
xrun "library(meboot)"
xrun "if (sum(.packages(TRUE)==""meboot"")==0) install.packages(""meboot"")"

xrun var1 <- rnorm(!n,0,1)
xrun var2 <- rnorm(!n,0,2)

xrun vars2 <- cbind(rep(1:2,rep(!n,2)),c(var1, var2))

xrun z<- meboot.pdata.frame(na.omit(vars2), reps = 20, trim=0.1, reachbnd = FALSE, expand.sd = FALSE, force.clt = TRUE, elaps = FALSE, colsubj= 1, coldata = 2)

xget(name = test1, test2 , type = matrix) z[,1:2] 'this does not work
'xget(name = test1 , type = vector) z[,1] this works but I want a matrix (there are many columns so vector by vector extraction would be inefficient

xclose


any help is greatly appreciated

Zeno

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: R and Eviews: using xget

Postby EViews Glenn » Fri Jul 23, 2010 9:06 am

If I'm understanding your question correctly, you should simply extract into the matrix using a single name ("test1"), not multiples ("test1 test2"). It will put the R matrix into an EViews matrix.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

Re: R and Eviews: using xget

Postby EViews Gareth » Fri Jul 23, 2010 9:11 am

I think, perhaps, he was trying to put the R matrix into multiple named EViews vectors in one step, which I think we don't support. You can bring it into EViews as a matrix, then extract the columns as vectors in a for loop though.

Zeno
Posts: 11
Joined: Thu Jan 08, 2009 9:47 am

Re: R and Eviews: using xget

Postby Zeno » Fri Jul 23, 2010 1:08 pm

I was trying to do the simple thing as Glenn suggested: just get the R matrix and convert it into an EViews matrix. The reason I was trying xget(name = test1, test2 , type = matrix) z[,1:2] is that I get the following error message: "The number of objects found do not match the number of names specified in name option (1 name(s) / 2 object(s))."

From the error message I understand that xget is looking for two names here.
However, I get the same error message using only one name argument.

thanks

Zeno

EViews Steve
EViews Developer
Posts: 844
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: R and Eviews: using xget

Postby EViews Steve » Mon Jul 26, 2010 7:58 am

Zeno:

Your z object is a data.frame that has column names with spaces in their names (e.g. "Pseries 1"). This is allowed in R but EViews will not support that currently -- we'll have to fix that in a future patch. There is a workaround though...

Your command:

Code: Select all

xget(name = test1, test2 , type = matrix) z[,1:2]
is getting a name count error because when EViews looks at the R object named "z[,1:2]", R is reporting that it is a data.frame with 2 columns, and the column names still have spaces in them. However, you can tell R to read the data.frame as a matrix like this:

Code: Select all

xget(name=test1, type=matrix) "as.matrix(z[,1:2])"
With the "as.matrix", EViews will see your expression as a single matrix instead of a data.frame with two separate columns. And in this case, you only need to specify a single EViews name.

Steve

Zeno
Posts: 11
Joined: Thu Jan 08, 2009 9:47 am

Re: R and Eviews: using xget

Postby Zeno » Mon Jul 26, 2010 8:27 am

Great! Thanks for the solution.

EViews Steve
EViews Developer
Posts: 844
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: R and Eviews: using xget

Postby EViews Steve » Mon Jul 26, 2010 8:59 am

By the way, I should've pointed out that whenever you want to read a data.frame with multiple columns into a single EViews matrix, you'll ALWAYS have to use the "as.matrix" conversion function, regardless if their column names have spaces in them or not.

EViews will always treat data.frames (or partial data.frames) as potentially multiple series or vector objects, each with their own name.

In regards to our documentation, it was always our intent on publishing a specific whitepaper on EViews/R integration that had more specifics than what is already in the User's Guide, but I haven't been able to get to it yet. I'll try to write this documentation as soon as possible, but I can't make any promises.

In the meantime, you can continue to ask questions in our forums and refer to older forum posts regarding this topic (there have been several already).

Steve


Return to “General Information and Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests