laviola
laviola

Reputation: 11

VAR Estimation Results to Latex by stargazer

I am trying to use the package Stargazer to "export" my estimation results into LaTeX code. I have read the stargazer manual and even tried to export selected rows without any luck. There are a lot of output for the package to handle.

I create an object

Summary <- summary(VAR(Vektorer, p=1, type="const", ic = c("AIC", "HQ", "SC", "FPE")))

Then, I use the stargazer package

stargazer(Summary)

and get the following error:

Error: Unrecognized object type.

Anyone familiar with this object type and how to export it into LaTeX code? I guess there re other packages which are more suitable for the object type. Unfortunately I am not very familiar with exporting R outputs into LaTeX.

Upvotes: 1

Views: 2616

Answers (3)

Pierre
Pierre

Reputation: 741

First, I assume that you are using the VAR function from vars. If so, do you really want to extract all the information at once from the summary function? Instead you could chose which information to present by Summary$varresult$´variable´.

Instead of using stargazer, I used xtable to produce the LaTeX code

library(vars)
library(xtable)

X <- cbind("A"=rnorm(100, 50), "B"=rnorm(100, 600, 50))

model <- VAR(X, p=1, type = "const", ic = c("AIC", "HQ", "SC", "FPE"))
tmp <- summary(model)

xtable(tmp$varresult$A)
xtable(tmp$varresult$B)

Also note all other possible output from tmp$.

Upvotes: 3

Bernardo Ostrovski
Bernardo Ostrovski

Reputation: 11

You must retrieve the right information in the var model output list. For example,

library(stargazer)

x1 <- 5 + 1.1*rnorm(100, 4, 2) + rnorm(100, 0, 2)
x2 <- runif(100, -1, 1)
y1 <-  x1/2 + rnorm(100, 0, 1)
y2 <- 10*sqrt(abs(x2)) - rpois(100, 3)

ts <- cbind(x1 , x2, y1, y2)

var_model <- VAR(ts[,c('y1','y2')],
                       lag.max = 1, ic = "AIC",
                       exogen = ts[,c('x1','x2')])

Now you must input only the information that stargazer will understand:

stargazer(var_model[["varresult"]], type = 'text')

Upvotes: 1

t-student
t-student

Reputation: 434

The problem is clear in the error message; stargazer does not understand the type of object you are passing it.

One option is to pass the underlying lm objects, which stargazer does know what to do with. Something along the lines of:

X <- cbind("A"=rnorm(100, 50), "B"=rnorm(100, 600, 50))
model <- VAR(X, p=1, type = "const", ic = c("AIC", "HQ", "SC", "FPE"))
stargazer::stargazer(model$varresult$A, model$varresult$B)

Upvotes: 1

Related Questions