简体   繁体   English

使用Knitr和stargazer的回归表

[英]Regression table using Knitr and stargazer

I am trying to use knitr and stargazer to export a regression table from R to Latex. 我正在尝试使用knitr和stargazer将回归表从R导出到Latex。 Unfortunately I get the following error message "Missing $ inserted" I've inserted a begin-math/end-math symbol since I think you left one out. 不幸的是我收到以下错误消息“Missing $ inserted”我插入了一个begin-math / end-math符号,因为我认为你留下了一个。 Proceed, with fingers crossed. 继续,用手指交叉。
Do I miss anything in my code or might this be an error from the stargazer package? 我是否会错过我的代码中的任何内容,或者这可能是stargazer包中的错误?
Any hints on how one can use knitr and stargazer together? 关于如何将knitr和stargazer一起使用的任何提示?

\documentclass{article}   
\begin{document}   
%Load dataset and run regression    

 << lm, echo=FALSE >>=  
load('dataset.RData')  
library(stargazer)  
lm1 <- lm(y~ x ,data=dataset)  
@


<< table_texstyle, echo=FALSE, comment=NA, results='asis' >>=  
stargazer(lm1)  
@  
\end{document}

stargazer v.2.0 is now out on CRAN, and should be able to deal with variable names that include dollar signs and underscore without any trouble. stargazer v.2.0现在已经出现在CRAN上,并且应该能够毫无困难地处理包含美元符号和下划线的变量名称。 Try installing the new version, and running your code again - you should not have any problems. 尝试安装新版本,然后再次运行代码 - 您应该没有任何问题。

It works well for me under Ubuntu 12.04, TeXLive 2012 and R 2.15.2. 在Ubuntu 12.04,TeXLive 2012和R 2.15.2下,它适用于我。

\documentclass{article}   
\begin{document}   
<<lm, echo=FALSE >>=  
df <- data.frame(x=1:10, y=rnorm(10))
library(stargazer)  
lm1 <- lm(y ~ x ,data=df)  
@

<<table_texstyle, echo=FALSE, results='asis' >>=  
stargazer(lm1)  
@  
\end{document}

You did not tell us what is dataset (we have no idea of your dataset.RData ), so we cannot really know what could be the reason of the failure. 你没有告诉我们什么是dataset (我们不知道你的dataset.RData ),所以我们真的不知道失败的原因是什么。 At least you need to paste the tex output like 至少你需要粘贴tex输出

% Table created by StarGazer v.1.0 by Marek Hlavac, Harvard University. E-mail: mhlavac at alumni.princeton.edu
% Date and time: Wed, Nov 14, 2012 - 06:20:12 PM
\begin{table}[htb] \centering 

....

\end{table}

so we know if the problem came from LaTeX. 所以我们知道问题是否来自LaTeX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM