Re: [R] Outreg-like command?

From: Dave Armstrong <davearmstrong.ps_at_gmail.com>
Date: Sat 06 May 2006 - 07:34:22 EST

Dear Thomas,

I'm not sure that you wanted something that outputs LaTeX code, but if so, here's a bit of code that I use. It doesn't take multiple models, so it's not exactly what you want, but with some trivial cutting and pasting, it should be ok. As you can see, it only tests significance at the 0.05 level, but that could be easily changed as well.

HTH,
Dave

 outreg <- function(object, fit=TRUE){

     coef <- coef(object)
     t.obj <- coef/sqrt(diag(vcov(object)[1:length(coef), 1:length(coef)]))
     s.e <- sqrt(diag(vcov(object)[1:length(coef), 1:length(coef)]))
     p.val <- 1-pnorm(abs(t.obj))
     out.mat <- matrix(NA, ncol=2, nrow=2*length(coef))
     l <- 1
     for(i in seq(from=1, to=2*length(coef), by=2)){
         out.mat[i, 1] <- if(p.val[l]<0.05) paste(round(coef[l], 3), "*",
sep="") else round(coef[l], 3)
         out.mat[i+1, 1] <- paste("(", paste(if(as.character(round(s.e[l],
3)) == "0") "0.000"
             else round(s.e[l], 3),  ")", sep=""), sep="")
         out.mat[i, 2] <- names(coef)[l]
         out.mat[i+1, 2] <- c("")
 l <- l+1
     }

 row.names(out.mat) <- out.mat[,2]
 out.mat <- cbind(rep("&", length(out.mat[,1])), out.mat[,1], rep(c("\\", " \\[.1in <file://%5B.1in/>]"), length(out.mat[,1])/2))  colnames(out.mat) <- c("", "", "")
 cat("\\begin{table}\n <file://begin%7Btable%7D/n>")
 cat("\\caption{}\n <file://caption%7B%7D/n>")
 cat("\\begin{center}\n <file://begin%7Bcenter%7D/n>")
 cat("\\begin{tabular}{ld{3}}\n <file://begin%7Btabular%7D%7Bld%7B3%7D%7D/n>
")
 cat("\\hline\n <file://hline/n>")
 cat(" &
\\multicolumn{1}{r}{Estimate<file://multicolumn%7B1%7D%7Br%7D%7BEstimate/>} \\\\\n")
 cat(" &
\\multicolumn{1}{r}{(S.E<file://multicolumn%7B1%7D%7Br%7D%7B(S.E/>.)} \\\\\n")
 cat("\\hline\\hline\n <file://hline//hline/n>")  print.table(out.mat)
 cat("\\hline\n <file://hline/n>")
 cat("\\multicolumn{2}{l}{N <file://multicolumn%7B2%7D%7Bl%7D%7BN/>=") cat(paste(object$df.residual + object$rank, "}\\\\\n", sep=""))  cat("\\multicolumn{2}{l}{*p$<$0.05<file://multicolumn%7B2%7D%7Bl%7D%7B*p$%3C$0.05/>, 2-sided}\\\\\n")
if(fit == TRUE){
     if(class(object)[1] == "lm"){
     cat("\\multicolumn{2}{l}{R$^{2}$<file://multicolumn%7B2%7D%7Bl%7D%7BR$%5E%7B2%7D$/>
=")
     cat(paste(round(summary(object)$r.squared, 3), "}\\\\\n", sep=""))
 }
     else if(class(object)[1] == "glm"){
         cat("\\multicolumn{2}{l}{deviance<file://multicolumn%7B2%7D%7Bl%7D%7Bdeviance/>
=")
         cat(paste(round(summary(object)$deviance, 3), "}\\\\\n", sep=""))
     }

 }
 cat("\\hline\\hline\n <file://hline//hline/n>")
 cat("\\end{tabular}\n <file://end%7Btabular%7D/n>")
 cat("\\end{center}\n <file://end%7Bcenter%7D/n>")
 cat("\\end{table}\n <file://end%7Btable%7D/n>")
 }

On 5/3/06, Thomas Davidoff <davidoff@haas.berkeley.edu> wrote:
>
> It would be nice to have something like stata's outreg that lets
> regression
> output go into a form like
> Specification (1) Specification (2)
> Var 1 coef(1,1) coef(1,2)
> se(1,1) se(1,2)
> Var 2 coef(2,1) coef(2,2)
> se(2,1) se(2,2)
>
> I don't think this can be done in xtable?
>
> Thomas Davidoff
> Assistant Professor
> Haas School of Business
> UC Berkeley
> Berkeley, CA 94618
> Phone: (510) 643-1425
> Fax: (510) 643-7357
> email: davidoff@haas.berkeley.edu
> web: http://faculty.haas.berkeley.edu/davidoff/
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

--
Dave Armstrong
University of Maryland
Dept of Government and Politics
3140 Tydings Hall
College Park, MD 20742
Office: 2103L Cole Field House
Phone: 301-405-9735
e-mail: darmstrong@gvpt.umd.edu
web: www.davearmstrong-ps.com

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat May 06 07:41:33 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 06 May 2006 - 10:10:01 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.