楼主: janyiyi
1100 1

Tailor Your Tables with stargazer: New Features for LaTeX and Text Output [推广有奖]

  • 3关注
  • 17粉丝

讲师

27%

还不是VIP/贵宾

-

威望
0
论坛币
3206 个
通用积分
5056.6800
学术水平
539 点
热心指数
537 点
信用等级
538 点
经验
10157 点
帖子
300
精华
2
在线时间
90 小时
注册时间
2010-10-3
最后登录
2024-4-6

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
By Tal Galili

Guest post by Marek Hlavac

Since its first introduction on this blog, stargazer, a package for turning R statistical output into beautiful LaTeX and ASCII text tables, has made a great deal of progress. Compared to available alternatives (such as apsrtable or texreg), the latest version (4.0) of stargazer supports the broadest range of model objects. In particular, it can create side-by-side regression tables from statistical model objects created by packages AER, betareg, dynlm, eha, ergm, gee, gmm, lme4, MASS, mgcv, nlme, nnet, ordinal, plm, pscl, quantreg, relevent, rms, robustbase, spdep, stats, survey, survival and Zelig.  You can install stargazer from CRAN in the usual way:

install.packages(“stargazer”)

New Features: Text Output and Confidence Intervals

In this blog post, I would like to draw attention to two new features of stargazer that make the package even more useful:

  • stargazer can now produce ASCII text output, in addition to LaTeX code. As a result, users can now create beautiful tables that can easily be inserted into Microsoft Word documents, published on websites, or sent via e-mail. Sharing your regression results has never been easier. Users can also use this feature to preview their LaTeX tables before they use the stargazer-generated code in their .tex documents.
  • In addition to standard errors, stargazer can now report confidence intervals at user-specified confidence levels (with a default of 95 percent). This possibility might be especially appealing to researchers in public health and biostatistics, as the reporting of confidence intervals is very common in these disciplines.

In the reproducible example presented below, I demonstrate these two new features in action.


Reproducible Example

I begin by creating model objects for two Ordinary Least Squares (OLS) models (using the lm() command) and a probit model (using glm() ). Note that I use data from attitude, one of the standard data frames that should be provided with your installation of R.


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:features feature output tables Tailor

已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
oliyiyi + 40 + 40 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 40  论坛币 + 40  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

沙发
janyiyi 发表于 2016-10-18 11:02:17 |只看作者 |坛友微信交流群
Reproducible Example

I begin by creating model objects for two Ordinary Least Squares (OLS) models (using the lm() command) and a probit model (using glm() ). Note that I use data from attitude, one of the standard data frames that should be provided with your installation of R.

  1. ## 2 OLS models

  2. linear.1 <- lm(rating ~ complaints + privileges + learning + raises + critical, data=attitude)
  3. linear.2 <- lm(rating ~ complaints + privileges + learning, data=attitude)

  4. ## create an indicator dependent variable, and run a probit model

  5. attitude$high.rating <- (attitude$rating > 70)
  6. probit.model <- glm(high.rating ~ learning + critical + advance, data=attitude, family = binomial(link = "probit"))
复制代码


I then use stargazer to create a ‘traditional’ LaTeX table with standard errors. With the sole exception of the argument no.space– which I use to save space by removing all empty lines in the table – both the command call and the resulting table should look familiar from earlier versions of the package:

  1. stargazer(linear.1, linear.2, probit.model, title="Regression Results", align=TRUE, dep.var.labels=c("Overall Rating","High Rating"), covariate.labels=c("Handling of Complaints","No Special Privileges", "Opportunity to Learn","Performance-Based Raises","Too Critical","Advancement"), omit.stat=c("LL","ser","f"), no.space=TRUE)
复制代码


In the next table, I limit myself to the two linear models, and report 90 percent confidence intervals (using the ci and ci.levelarguments). In addition, I use the argument single.row to report the coefficients and confidence intervals on the same row.

  1. stargazer(linear.1, linear.2, title="Regression Results",
  2. dep.var.labels=c("Overall Rating","High Rating"),
  3. covariate.labels=c("Handling of Complaints","No Special Privileges",
  4. "Opportunity to Learn","Performance-Based Raises","Too Critical","Advancement"), omit.stat=c("LL","ser","f"), ci=TRUE, ci.level=0.90, single.row=TRUE)
复制代码


To produce ASCII text output, rather than LaTeX code, I can simply set the argument type to “text”:

  1. stargazer(linear.1, linear.2, type="text", title="Regression Results",
  2. dep.var.labels=c("Overall Rating","High Rating"),
  3. covariate.labels=c("Handling of Complaints","No Special Privileges",
  4. "Opportunity to Learn","Performance-Based Raises","Too Critical","Advancement"), omit.stat=c("LL","ser","f"), ci=TRUE, ci.level=0.90, single.row=TRUE)
复制代码


What Else is New?

The two new features that I have focused on in this blog post, of course, do not exhaust the range of innovations that the new stargazer brings. The package can now output beautiful LaTeX and ASCII text tables directly into .tex and.txt files, respectively, using the out argument.

Additionally, users have a greater scope for making changes to the table’s formatting. A much-demanded addition to version 4.0 concerns column labels. Using arguments column.labels and column.separate, users can now add a label to each of the columns in their regression table. Such labels can be used to indicate, among other things, the sub-sample or research hypothesis that a particular column refers to. In addition, users can also change the caption above the names of the dependent variables (argument dep.var.caption), as well as tinker with the font size in the resulting table (argument font.size).

More advanced users can now choose whether the LaTeX table should be enclosed within a floating environment (arguments floatand float.env), and where the resulting table should be placed within the LaTeX document (argument table.placement). In this way, they might, for example, create a LaTeX table  that is rotated by 90 degrees (when float.env = “sidewaystable”).

Marek Hlavac is a doctoral student in the Political Economy and Government program at Harvard Unviersity. If you have any suggestions for future versions of the stargazer package, please contact him at hlavac@fas.harvard.edu .


已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
oliyiyi + 20 + 20 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 20  论坛币 + 20  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 12:57