Descriptive statistics: in text format, replacing variable names with labels
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"))
OTR
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
============================================================
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
------------------------------------------------------------
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
5