Skip to content
Prev 307656 / 398506 Next

Exporting summary plm results to latex

Hi,

I tried this function on an example dataset and it seems to be working.
extract.plm <- function(model) {

if (!class(model)[1] == "plm") {
stop("Internal error: Incorrect model type! Should be a plm object!")
}
zz1<-summary(model)$coef[,1:2]
?zz2<-as.data.frame(apply(zz1,2,function(x) sprintf("%.3f",x)))
zz2[]<-sapply(zz2,function(x) as.numeric(as.character(x)))
zz3<-data.frame(Coefficient=row.names(zz1),zz2)
zz3<-melt(zz3,by=Coefficient)
zz4<-within(zz3,{Coefficient<-as.character(Coefficient);variable<-as.character(variable)})
zz5<-ddply(zz4,.(Coefficient),function(x) x)
zz5$value[zz5$variable=="Estimate"]
zz5$value[zz5$variable=="Std..Error"]
zz5$value[zz5$variable=="Estimate"]<-ifelse(summary(model)$coef[,4]<0.05& summary(model)$coef[,4]>=0.01, gsub("(.*)","\\1*",zz5$value[zz5$variable=="Estimate"]),ifelse(summary(model)$coef[,4]<0.01,gsub("(.*)","\\1**",zz5$value[zz5$variable=="Estimate"]),zz5$value[zz5$variable=="Estimate"]))
zz5$value[zz5$variable=="Std..Error"]<-gsub("(.*)","(\\1)",zz5$value[zz5$variable=="Std..Error"])
res<-zz5[,c(1,3)]
res
}

data("Produc", package = "plm")
zz <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, index = c("state","year"))
#Using Coefficient as id variables
?# Coefficient??? value
#1??? log(emp)??? 0.768
#2??? log(emp)?? (0.03)
#3???? log(pc)? 0.292**
#4???? log(pc)? (0.025)
#5?? log(pcap) -0.026**
#6?? log(pcap)? (0.029)
#7?????? unemp -0.005**
#8?????? unemp? (0.001)
library(xtable)
?xtable(extract.plm(zz))
Using Coefficient as id variables
% latex table generated in R 2.15.0 by xtable 1.7-0 package
% Thu Oct 11 09:43:00 2012
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
? \hline
?& Coefficient & value \\ 
? \hline
1 & log(emp) & 0.768 \\ 
? 2 & log(emp) & (0.03) \\ 
? 3 & log(pc) & 0.292** \\ 
? 4 & log(pc) & (0.025) \\ 
? 5 & log(pcap) & -0.026** \\ 
? 6 & log(pcap) & (0.029) \\ 
? 7 & unemp & -0.005** \\ 
? 8 & unemp & (0.001) \\ 
?? \hline
\end{tabular}
\end{center}
\end{table}

A.K.





----- Original Message -----
From: Sebastian Barfort <sb3730 at nyu.edu>
To: Duncan Mackay <mackay at northnet.com.au>
Cc: r-help-r-project.org <r-help at r-project.org>
Sent: Wednesday, October 10, 2012 7:45 PM
Subject: Re: [R] Exporting summary plm results to latex

I am also interested in the standard errors, but beneath not next to the point estimates which is standard in the xtable package. 
If you by any chance remember the name of the package or how to do it that would be much appreciated!

Cheers,
Sebastian
On Oct 10, 2012, at 7:10 PM, Duncan Mackay <mackay at northnet.com.au> wrote:

            
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.