Using stargazer to report regression output and descriptive statistics in R (for non-latex users) (v1.0 draft)



Similar documents
OVERVIEW OF R SOFTWARE AND PRACTICAL EXERCISE

Using outreg2 to report regression output, descriptive statistics, frequencies and basic crosstabulations (v1.6 draft)

A Short Guide to R with RStudio

1. What is the critical value for this 95% confidence interval? CV = z.025 = invnorm(0.025) = 1.96

Data Visualization with R Language

Introduction to RStudio

Research Report. Impact of Vehicle Weight Reduction on Fuel Economy for Various Vehicle Architectures

Kubota Tractor B50 Cab

MATH 110 Automotive Worksheet #4

Introduction to Learning & Decision Trees

MAS8381: Statistics for Big data Part 2: Multivariate Data Analysis using R

Exporting Client Information

An Application of Weibull Analysis to Determine Failure Rates in Automotive Components

1 Air-to-Air AfterCooling. 2 Engine Only. Capacity will vary with radiator size and use. of cab heater.

<next> <PDF version> Tutorial: Automated table generation and reporting with Stata. Ben Jann, ETH Zurich,

Exporting Contact Information

SPSS: Getting Started. For Windows

Using the SAS Enterprise Guide (Version 4.2)

1 Stock & Suppliers mini Guide

7 Steps to Successful Data Blending for Excel

>

RT100 ROUGH TERRAIN CRANE DATASHEET - IMPERIAL. Features:

Psychology 205: Research Methods in Psychology

Estimation of σ 2, the variance of ɛ

ECONOMICS 351* -- Stata 10 Tutorial 2. Stata 10 Tutorial 2

Polynomial Neural Network Discovery Client User Guide

Multiple Linear Regression

Creating CSV Files. Recording Data in Spreadsheets

Module 2 Basic Data Management, Graphs, and Log-Files

Fuel Economy Comparison

New Holland T7.270 Auto Command

EDGE PRODUCTS EVOLUTION CS and CTS DIESEL POWER LEVELS AND SUPPORTED VEHICLE PARAMETERS (PIDs) [85100 and 85200]

View our AppExchange listing for AddressTools here:

ELECTRONIC CONTROLS. Filter Life

SAS: A Mini-Manual for ECO 351 by Andrew C. Brod

Computer Training Centre University College Cork. Excel 2013 Pivot Tables

ESTIMATED RECOVERY GENERATOR DATASET

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

Advanced Light-Duty Powertrain and Hybrid Analysis (ALPHA) Tool User s Guide for Off-Cycle Credit Evaluation

Evaluating the results of a car crash study using Statistical Analysis System. Kennesaw State University

Features, Benefits, and Operation

7. Data Packager: Sharing and Merging Data

Step 2: Save the file as an Excel file for future editing, adding more data, changing data, to preserve any formulas you were using, etc.

Methods for Interaction Detection in Predictive Modeling Using SAS Doug Thompson, PhD, Blue Cross Blue Shield of IL, NM, OK & TX, Chicago, IL

Quick DDNS Quick Start Guide

10 Listing data and basic command syntax

Name: Partners: Period: Coaster Option: 1. In the space below, make a sketch of your roller coaster.

With an excellent weight-to-power ratio of 37 kg/hp, the C-L model is ideal for general field work, as well as for PTO and transport applications.

The only counter top model for high volume production

Creating Tables and Queries in MS Access

Set Top Box User Guide. Global Reach with a Local Touch

Executive Guide to Fleet Fuel Economy Part 1 of 2: Vehicle Configuration and Operating Factors Emphasizing Fuel Economy Pays Off...

RELIABILITY DURABILITY

Propane as the Alternate Fuel for Fleets

Chapter 6 - Condor finder

from Microsoft Office

RT 780. RT USt Lifting Capacity Rough Terrain Cranes Datasheet Imperial. Features

Big Data Decision Trees with R

Merge/Append using R (draft)

Dell KACE K1000 Management Appliance. Asset Management Guide. Release 5.3. Revision Date: May 13, 2011

CCBill Traffic Manager

Budgeting and Measuring Your Financial Health. Assignments

The Easy-to-use Steering Design Tool SimuLENK as an Application of SIMPACK Code Export

Decision Trees from large Databases: SLIQ

Introduction. Notice anything missing from this manual? Please contact and help us improve!

Elektrofahrzeug mit Range Extender die Entwicklungsherausforderung Electric Vehicle with Range Extender. The developement challenge

Creating a Simple Macro

4500 SERIES. 97% Customer Satisfaction Rating 98% Customer Loyalty Rating. #1 Selling Tractor in the World 5-year Powertrain Warranty

SalesCTRL Release Notes

Alternative Fuel Sedans Section 1: Line Item Number (Mandatory)

Bulk Downloader. Call Recording: Bulk Downloader

ln(p/(1-p)) = α +β*age35plus, where p is the probability or odds of drinking

Better credit models benefit us all

THE STYLISH, SPORTY. SCION tc

RACING BUGGY The Racing Buggy represents Fornasari s attitude to innovation and creativity. Introduced in 2010, it is a car which combines the Fornasa

Directions for using SPSS

Descriptive Statistics

Universal Simple Control, USC-1

Tutorial 3: Graphics and Exploratory Data Analysis in R Jason Pienaar and Tom Miller

Monster Mini Stock Assn rules for 2015

Electric Motors and Drives

Linear Static Analysis of a Cantilever Beam Using Beam Library (SI Units)

Sample Salvage Vehicle Report

outreg help pages Write formatted regression output to a text file After any estimation command: (Text-related options)

Corsa kW/60hp 5-speed hatchback 3 doors 1

CPS-3 Pallet Jack Scale

Forms Printer User Guide

Linear smoother. ŷ = S y. where s ij = s ij (x) e.g. s ij = diag(l i (x)) To go the other way, you need to diagonalize S

CowCalf5. for Dummies. Quick Reference. D ate: 3/26 /

Lecture 6: Logistic Regression

Digital Adrenaline For Your. Volvo V50 T5 5cyl

TRUCKS AND HAULING EQUIPMENT

CX (T3), great performance for unlimited versatility

CCC Report Center Overview Accessing the CCC Report Center Accessing, Working With, and Running Reports Customizing Reports...

Transcription:

Using stargazer to report regression output and descriptive statistics in R (for non-latex users) (v1.0 draft) Oscar Torres-Reyna otorres@princeton.edu May 2014 http://dss.princeton.edu/training/

Introduction As anything with R, there are many ways of exporting output into nice tables (but mostly for LaTeX users). Some packages are: apsrtable, xtable, texreg, memisc, outreg and counting. At the moment, the new kid on the block is stargazer. Released by Marek Hlavac on March 3 rd, 2014, version 5.0 offers a very nice, smart, and easy-to-use alternative to non-latex users, in particular, the ability to import editable tables into a Word document. This presentation will show some of the options stargazer offers, the contents are based on the documentation from the package available in the following links: http://cran.r-project.org/web/packages/stargazer/stargazer.pdf http://cran.r-project.org/web/packages/stargazer/vignettes/stargazer.pdf The default setting produces LaTeX code, the additional alternatives are: Output as text, which allows a quick view of results Output as html, which produce editable tables for Word documents. 2

For a quick view of the results use the text format option OUTPUT IN TEXT FORMAT 3

Descriptive statistics: in text format mydata <- mtcars install.packages("stargazer") #Use this to install it, do this only once library(stargazer) stargazer(mydata, type = "text", title="descriptive statistics", digits=1, out="table1.txt") stargazer will automatically recognize the type of object, and will produce the appropriate output. In the case of data frames, it will display summary statistics. Descriptive statistics ====================================== Statistic N Mean St. Dev. Min Max mpg 32 20.1 6.0 10.4 33.9 cyl 32 6.2 1.8 4 8 disp 32 230.7 123.9 71.1 472.0 hp 32 146.7 68.6 52 335 drat 32 3.6 0.5 2.8 4.9 wt 32 3.2 1.0 1.5 5.4 qsec 32 17.8 1.8 14.5 22.9 vs 32 0.4 0.5 0 1 am 32 0.4 0.5 0 1 gear 32 3.7 0.7 3 5 carb 32 2.8 1.6 1 8 -------------------------------------- The table will be saved in the working directory with whatever name you write in the out option. You can open this file with any word processor # Same output, transposed (variables in columns) stargazer(mydata, type = "text", title="descriptive statistics", digits=1, out="table1.txt", flip=true) For more details/options type?stargazer Descriptive statistics ============================================================== Statistic mpg cyl disp hp drat wt qsec vs am gear carb N 32 32 32 32 32 32 32 32 32 32 32 Mean 20.1 6.2 230.7 146.7 3.6 3.2 17.8 0.4 0.4 3.7 2.8 St. Dev. 6.0 1.8 123.9 68.6 0.5 1.0 1.8 0.5 0.5 0.7 1.6 Min 10.4 4 71.1 52 2.8 1.5 14.5 0 0 3 1 Max 33.9 8 472.0 335 4.9 5.4 22.9 1 1 5 8 -------------------------------------------------------------- Use this option if you want the variables in columns 4

Descriptive statistics: in text format, replacing variable names with labels The table will be saved in the working directory with whatever name you write in the out option. You can open this file with any word processor mydata <- mtcars install.packages("stargazer") #Use this to install it, do this only once library(stargazer) stargazer(mydata, type = "text", title="descriptive statistics", digits=1, out="table1.txt", covariate.labels=c("miles/(us)gallon","no. of cylinders","displacement (cu.in.)", "Gross horsepower","rear axle ratio","weight (lb/1000)", "1/4 mile time","v/s","transmission (0=auto, 1=manual)", "Number of forward gears","number of carburetors")) Use the option covariate.labels to replace variable names with variable labels. Must be in same order as in the dataset. For more details/options type?stargazer Descriptive statistics ============================================================ Statistic N Mean St. Dev. Min Max Miles/(US)gallon 32 20.1 6.0 10.4 33.9 No. of cylinders 32 6.2 1.8 4 8 Displacement (cu.in.) 32 230.7 123.9 71.1 472.0 Gross horsepower 32 146.7 68.6 52 335 Rear axle ratio 32 3.6 0.5 2.8 4.9 Weight (lb/1000) 32 3.2 1.0 1.5 5.4 1/4 mile time 32 17.8 1.8 14.5 22.9 V/S 32 0.4 0.5 0 1 Transmission (0=auto, 1=manual) 32 0.4 0.5 0 1 Number of forward gears 32 3.7 0.7 3 5 Number of carburetors 32 2.8 1.6 1 8 ------------------------------------------------------------ 5

Descriptive statistics: in text format, selected variables mydata <- mtcars install.packages("stargazer") #Use this to install it, do this only once library(stargazer) stargazer(mydata[c("mpg","hp","drat")], type = "text", title="descriptive statistics/selected variables", digits=1, out="table2.txt") Descriptive statistics/selected variables ===================================== Statistic N Mean St. Dev. Min Max mpg 32 20.1 6.0 10.4 33.9 hp 32 146.7 68.6 52 335 drat 32 3.6 0.5 2.8 4.9 ------------------------------------- The table will be saved in the working directory with whatever name you write in the out option. You can open this file with any word processor #same output transposed and with labels instead of variable names stargazer(mydata[c("mpg","hp","drat")], type = "text", title="descriptive statistics/selected variables", digits=1, out="table2.txt", flip=true, covariate.labels=c("miles/(us)gallon","gross horsepower","rear axle ratio")) Use the option covariate.labels to replace variable names with variable labels. Must be in same order as in the dataset. Descriptive statistics/selected variables =========================================================== Statistic Miles/(US)gallon Gross horsepower Rear axle ratio N 32 32 32 Mean 20.1 146.7 3.6 St. Dev. 6.0 68.6 0.5 Min 10.4 52 2.8 Max 33.9 335 4.9 ----------------------------------------------------------- Use this option if you want the variables in columns For more details/options type?stargazer 6

Descriptive statistics: in text format, selected variables, and by group mydata <- mtcars install.packages("stargazer") #Use this to install it, do this only once library(stargazer) # Descriptive statistics for cars with automatic transmission stargazer(subset(mydata[c("mpg","hp","drat")], mydata$am==0), title="automatic transmission", type = "text", digits=1, out="table3.txt") Use subset() to select the category Automatic transmission ===================================== Statistic N Mean St. Dev. Min Max mpg 19 17.1 3.8 10.4 24.4 hp 19 160.3 53.9 62 245 drat 19 3.3 0.4 2.8 3.9 ------------------------------------- The table will be saved in the working directory with whatever name you write in the out option. You can open this file with any word processor # Descriptive statistics for cars with manual transmission stargazer(subset(mydata[c("mpg","hp","drat")], mydata$am==1), title="manual transmission", type = "text", digits=1, out="table4.txt") Use subset() to select the category Manual transmission ===================================== Statistic N Mean St. Dev. Min Max mpg 13 24.4 6.2 15.0 33.9 hp 13 126.8 84.1 52 335 drat 13 4.0 0.4 3.5 4.9 ------------------------------------- For more details/options type?stargazer 7

Regression models: in text format mydata$fast <- as.numeric((mydata$mpg > 20.1)) #Creating a dummy variable 1 = fast car m1 <- lm(mpg ~ hp, data=mydata) The table will be saved in the m2 <- lm(mpg ~ hp + drat, data=mydata) working directory with whatever m3 <- lm(mpg ~ hp + drat + factor(gear), data=mydata) name you write in the out m4 <- glm(fast ~ hp + drat + am, family=binomial(link="logit"), data=mydata) option. You can open this file stargazer(m1, m2, m3, m4, type="text", with any word processor dep.var.labels=c("miles/(us) gallon","fast car (=1)"), covariate.labels=c("gross horsepower","rear axle ratio","four foward gears", "Five forward gears","type of transmission (manual=1)"), out="models.txt") For the output, you have the option to use variable labels instead of variable names (according to the type of model) For the predictors, you have the option to use variable labels instead of variable names (in order they appear) For more details/options type?stargazer 8

For a nice presentation use the html option, open it with any word processor OUTPUT IN HTML FORMAT 9

Regression models: in html format mydata$fast <- as.numeric((mydata$mpg > 20.1)) #Creating a dummy variable 1 = fast car m1 <- lm(mpg ~ hp, data=mydata) The table will be saved in the m2 <- lm(mpg ~ hp + drat, data=mydata) working directory with whatever m3 <- lm(mpg ~ hp + drat + factor(gear), data=mydata) name you write in the out m4 <- glm(fast ~ hp + drat + am, family=binomial(link="logit"), data=mydata) option. You can open this file stargazer(m1, m2, m3, m4, type="html", with any word processor dep.var.labels=c("miles/(us) gallon","fast car (=1)"), covariate.labels=c("gross horsepower","rear axle ratio","four foward gears", "Five forward gears","type of transmission (manual=1)"), out="models.htm") For the output, you have the option to use variable labels instead of variable names (according to the type of model) For the predictors, you have the option to use variable labels instead of variable names (in order they appear) In the type option write html to export R results to html. It may be a good idea to use the appropriate extension in the out option, in this example the results will be saved in the file models.htm. Word can easily read *.htm files, making tables easily editable. Files should look like the example shown here. Same apply to the other procedures described in the previous section. For more details/options type?stargazer 10