2016-07-08 4 views
2

を使用しています。この分数回帰は、taus:です。私は、テーブルを構築したいLATEXのQuantile Regression出力は、R

taus <-c(.05,.10,.15,.20,.25,.30,.35,.40,.45,.50,.55,.60,.65,.70,.75,.80,.85,.90,.95) 
fit1_List<-list() 
for(i in 1:length(taus)) { 
    fit1_List[[i]]<-rq(foodexp~xx,tau =taus[i],method="br") 

} 

stargazer

stargazer(fit1_List, 
      intercept.bottom = FALSE, 
      rq.se="nid",ci=TRUE, ci.level=0.90, 
      style = "qje", 
      title="Quantile Regression Results", align=TRUE, 
      dep.var.caption = "",model.numbers = TRUE 
      , t.auto = TRUE, p.auto = TRUE, 
      font.size="scriptsize", keep.stat="aic", 

      dep.var.labels = "",multicolumn = TRUE 

      ,dep.var.labels.include = TRUE) 

を使用して結果は次のとおりです。

\begin{table}[!htbp] \centering 
    \caption{Quantile Regression Results} 
    \label{} 
\scriptsize 
\begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} } 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
\\[-1.8ex] & \multicolumn{19}{c}{} \\ 
\\[-1.8ex] & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)} & \multicolumn{1}{c}{(7)} & \multicolumn{1}{c}{(8)} & \multicolumn{1}{c}{(9)} & \multicolumn{1}{c}{(10)} & \multicolumn{1}{c}{(11)} & \multicolumn{1}{c}{(12)} & \multicolumn{1}{c}{(13)} & \multicolumn{1}{c}{(14)} & \multicolumn{1}{c}{(15)} & \multicolumn{1}{c}{(16)} & \multicolumn{1}{c}{(17)} & \multicolumn{1}{c}{(18)} & \multicolumn{1}{c}{(19)}\\ 
\hline \\[-1.8ex] 
Constant & 462.223^{***} & 504.866^{***} & 527.975^{***} & 541.381^{***} & 561.277^{***} & 571.916^{***} & 586.173^{***} & 602.919^{***} & 623.829^{***} & 631.845^{***} & 645.349^{***} & 655.283^{***} & 668.013^{***} & 677.463^{***} & 695.123^{***} & 705.958^{***} & 717.999^{***} & 741.622^{***} & 760.745^{***} \\ 
    & \multicolumn{1}{c}{(431.899$, $492.548)} & \multicolumn{1}{c}{(481.055$, $528.677)} & \multicolumn{1}{c}{(507.211$, $548.740)} & \multicolumn{1}{c}{(523.405$, $559.357)} & \multicolumn{1}{c}{(544.158$, $578.396)} & \multicolumn{1}{c}{(554.395$, $589.437)} & \multicolumn{1}{c}{(567.408$, $604.938)} & \multicolumn{1}{c}{(585.782$, $620.056)} & \multicolumn{1}{c}{(606.506$, $641.152)} & \multicolumn{1}{c}{(614.249$, $649.440)} & \multicolumn{1}{c}{(627.930$, $662.768)} & \multicolumn{1}{c}{(640.077$, $670.489)} & \multicolumn{1}{c}{(651.814$, $684.211)} & \multicolumn{1}{c}{(663.463$, $691.464)} & \multicolumn{1}{c}{(681.002$, $709.245)} & \multicolumn{1}{c}{(690.350$, $721.566)} & \multicolumn{1}{c}{(704.852$, $731.146)} & \multicolumn{1}{c}{(725.196$, $758.047)} & \multicolumn{1}{c}{(749.225$, $772.265)} \\ 
    & & & & & & & & & & & & & & & & & & & \\ 
xx & 0.343^{***} & 0.402^{***} & 0.424^{***} & 0.447^{***} & 0.474^{***} & 0.481^{***} & 0.489^{***} & 0.510^{***} & 0.552^{***} & 0.560^{***} & 0.566^{***} & 0.586^{***} & 0.605^{***} & 0.609^{***} & 0.644^{***} & 0.660^{***} & 0.678^{***} & 0.686^{***} & 0.709^{***} \\ 
    & \multicolumn{1}{c}{(0.261$, $0.425)} & \multicolumn{1}{c}{(0.336$, $0.468)} & \multicolumn{1}{c}{(0.366$, $0.482)} & \multicolumn{1}{c}{(0.398$, $0.496)} & \multicolumn{1}{c}{(0.426$, $0.522)} & \multicolumn{1}{c}{(0.432$, $0.530)} & \multicolumn{1}{c}{(0.439$, $0.539)} & \multicolumn{1}{c}{(0.462$, $0.558)} & \multicolumn{1}{c}{(0.505$, $0.600)} & \multicolumn{1}{c}{(0.514$, $0.607)} & \multicolumn{1}{c}{(0.519$, $0.612)} & \multicolumn{1}{c}{(0.545$, $0.627)} & \multicolumn{1}{c}{(0.565$, $0.644)} & \multicolumn{1}{c}{(0.573$, $0.645)} & \multicolumn{1}{c}{(0.606$, $0.682)} & \multicolumn{1}{c}{(0.616$, $0.703)} & \multicolumn{1}{c}{(0.640$, $0.715)} & \multicolumn{1}{c}{(0.639$, $0.733)} & \multicolumn{1}{c}{(0.680$, $0.739)} \\ 
    & & & & & & & & & & & & & & & & & & & \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Notes:} & \multicolumn{19}{r}{$^{***}$Significant at the 1 percent level.} \\ 
& \multicolumn{19}{r}{$^{**}$Significant at the 5 percent level.} \\ 
& \multicolumn{19}{r}{$^{*}$Significant at the 10 percent level.} \\ 
\end{tabular} 
\end{table} 

あなたはフォーマットが水平で見ることができるように。私はどのように垂直に置くのですか?つまり、最終的に私は2つの列しか持たないでしょう。

そして最も重要なのは、アスタリスクの重要性を保つことです。

答えて

0

stargazerでこれを行う簡単な方法はありません。 stargazerユーザとして、私はこのパッケージの一般化のためにいくつかのユーザ定義関数を作成しました。追加のコーディングの後に、あなたの望む結果に近いものが得られます。例えば

は、

taus <-c(.05,.10,.15,.20,.25,.30,.35,.40,.45,.50,.55,.60,.65,.70,.75,.80,.85,.90,.95) 
fit1_List<-list() 

#First I save all the coef and test statistics from the specifications. Notice I use the iris data set since you did not provide data. 

MYcoef <- matrix(NA, nrow = length(taus), ncol = 2) 
MYteststat <- matrix(NA, nrow = length(taus), ncol = 2) 
for(i in 1:length(taus)) { 
    res <- rq(iris$Sepal.Length ~ iris$Sepal.Width, tau = taus[i], method = "br") 
    MYcoef[i, ] <- res$coef 
    MYteststat[i, ] <- summary(res, se = "nid")$coef[, 3] 
} 

#Then utilize my user defined function, myStars, to star all the coefficients. This little function is really helpful and I use it all the time when reporting results. 

myStars <- function(testStat, cval, sig_dig, coef = FALSE, coefValue = NULL){ 
    testStat<- round(testStat, sig_dig) 

    if(!is.matrix(testStat)) 
    test <- matrix(testStat, length(cval), 1) 

    if(!is.matrix(cval)) 
    cval <- matrix(cval, 1, length(cval)) 

    test <- matrix(rep(testStat, ncol(cval)),nrow(cval), ncol(cval)) 

    starCount <- rowSums(abs(test) > abs(cval)) 

    stars <- sapply(starCount, function(x) paste(rep("*", x), collapse = "")) 

    if(coef) 
    paste0(round(coefValue, sig_dig), stars) 
    else 
    paste0(testStat, stars) 
} 



#I don't know much about QR, however, I suspect the critical values are incorrect below. 

MYcoefStars <- matrix(NA, nrow = length(taus), ncol = 2) 
for(i in 1:nrow(MYcoef)){ 
    for(j in 1:ncol(MYcoef)){ 
    MYcoefStars[i,j] <- myStars(MYteststat[i, j], c(1.64, 1.96, 2.33), 2, coef = TRUE, coefValue = MYcoef[i, j]) 
    } 
} 

#Finally, I've starred all the coefficients, however, stargazer is going to interpret the asterisk as a undesirable latex character. The below user defined function fixStar, as its names suggests, fixes this. It is essentially a wrapper for stargazer, so you can pass it any stargazer argument you like. 

fixStar <- function(x,...){ 
    tbl <- capture.output(stargazer(x, ...)) 
    undo <- gsub("\\\\textasteriskcentered", "*", tbl) 
    restar <- gsub("* * *", "${}^{***}$", undo, fixed = TRUE) 
    restar <- gsub("* *", "${}^{**}$", restar, fixed = TRUE) 
    restar <- gsub("* ", "${}^{*}$", restar, fixed = TRUE) 
    cat(restar, sep="\n") 
} 

fixStar(MYcoefStars) 

これがあなたの道のほとんどを取得する必要があります。テーブルのフォーマットには作業が必要であり、ラテックスでいくつかのコーディングを行う必要があります。つまり、上記の2つのユーザ定義関数は、仲間のstargazerに使用される可能性があります。

関連する問題