Stargazer changing position of dependent variable

Asked

Viewed 219 times

6

Considering the quantile regressions.

library(quantreg)

> x=rnorm(100,12,2)
> y=rnorm(100,0,4)

a<-rq(y~x,tau = .10)
b<-rq(y~x,tau = .15)
c<-rq(y~x,tau = .20)
d<-rq(y~x,tau = .25)

As I only have a constant and an explanatory variable I would like to put as columns X and the constant, ie "transpose" the result that the package stargazer offers me, which is the opposite of this one:

stargazer(a,b,c,d,title="Regression Results",align=TRUE, dep.var.caption="",model.numbers=TRUE,intercept.bottom=FALSE,font.size="scriptsize",keep.stat="aic",dep.var.labels="",multicolumn=TRUE,ci=TRUE,ci.level=0.90,dep.var.labels.include=TRUE)

The stargazer generates a table like this: inserir a descrição da imagem aqui

What I want is that each tau is on the lines, thus having a table with tau´s rows and 2 columns.

There’s like?

  • Hello Diogo. Important tip to make it easier for you to get help more quickly/easily: build and deliver a [mcve].

1 answer

1

Difficult to leave as complete as the table produced by stargazer, if you can simplify it, you can do so:

modelos <- list(a,b,c,d)
param <- plyr::ldply(modelos, function(x) coef(x))
param <- cbind(data.frame(tau = seq(0.1, 0.25, by = 0.05)),
               param)

xtable::xtable(param)

He will produce the following Latex

% latex table generated in R 3.2.1 by xtable 1.8-2 package
% Mon May 23 15:34:54 2016
\begin{table}[ht]
\centering
\begin{tabular}{rrrr}
  \hline
 & tau & (Intercept) & x \\ 
  \hline
1 & 0.10 & -12.75 & 0.61 \\ 
  2 & 0.15 & -9.13 & 0.41 \\ 
  3 & 0.20 & -7.15 & 0.29 \\ 
  4 & 0.25 & -5.52 & 0.19 \\ 
   \hline
\end{tabular}
\end{table}

What compiled gives this table:

inserir a descrição da imagem aqui

Remember to have the packages installed plyr and xtable, using install.packages("nome_do_pacote").

The xtable has several options of table configuration, you can take a look at this link to learn more.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.