AN EXAMPLE OF MODEL SUMMARIES IN R

Download R source file


              # An example of model summaries in R
# Author: Jake Fisher

# Set up workspace
rm(list = ls())
setwd("C:/Users/fishe/Dropbox/SN&H Files/SampleData")  
# install.packages("stargazer")
library(stargazer)

# Load the faux Add Health data
dat <- read.csv("ahs_wpvar.csv", stringsAsFactors = FALSE)

# Run a series of models
models <- c(
  POP_BEH ~ IDG_SS + grade,
  POP_BEH ~ grade,
  POP_BEH ~ sex
)

# stargazer doesn't play nicely with model fits created from lapply, so we have
# to write this as an anonymous function
fits <- lapply(models, function(x) lm(x, data = dat))

# Print the table
stargazer(fits, type = "text")

# You can do HTML and LaTeX output too, you can save it, modify names of the
# variables, etc..  Check out all the options in the help file:
?stargazer