2

I have recently installed R to work on a dataset for a University project.

After succesfully downloading the package "stargazer" in R Studio and loading it into my script, I imported my dataset from an excel sheet.

However,whenever I run the stargazer command in a very simple form (see Picture), I dont get any output.

I am new to R, so is there anything obvious that I am missing in order to run the stargazer command properly?

I am working on MacOSX 10.12.4 and R 3.3.1

Branko Castro
  • 23
  • 1
  • 3
  • On my PC `stargazer(attitude, type="text")` works and generates a table. You should post the content of `R_trial`. – Marco Sandri May 11 '17 at 19:43
  • 1
    Pictures of screens are of very little help. To post a [MCVE] one needs to paste text into the question by [edit]-ing. – IRTFM May 11 '17 at 20:07
  • @MarcoSandri, this is my code: install.packages("stargazer") library(stargazer) stargazer(R_trial, type="text", title="descriptive statistics", digits=1, out="table1.txt") Is it possible to send you my excel sheet somehow? maybe that's more of help to you. – Branko Castro May 11 '17 at 20:30
  • Thanks first of all. I could only send the lower part since the rest was a long output of numbers this is what I got: .Names = c("BLOCK_5PCT", "INDEP_TOTBLOCK", "INDEP_5pctBLOCK", "BRD_DEP_PCT", "FIRM_SIZE", "LEVERAGE", "FCF", "Tobins_Q", "DEAL_SIZE", "D_PUBLIC", "D_PRIVATE", "D_SUBSIDIARY", "D_DIVERSIFY", "ALL_CASH", "ALL_EQUITY"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -1064L)) – Branko Castro May 11 '17 at 20:45
  • This is what I get then: structure(list(D_PUBLIC = c(0, 0, 0, 1, 0, 1), D_PRIVATE = c(1, 1, 1, 0, 0, 0), D_SUBSIDIARY = c(0, 0, 0, 0, 1, 0), D_DIVERSIFY = c(1, 0, 0, 0, 0, 0), ALL_CASH = c(0, 0, 0, 0, 0, 0), ALL_EQUITY = c(1, 0, 1, 1, 0, 0)), .Names = c("BLOCK_5PCT", "INDEP_TOTBLOCK", "INDEP_5pctBLOCK", "BRD_DEP_PCT", "FIRM_SIZE", "LEVERAGE", "FCF", "Tobins_Q", "DEAL_SIZE", "D_PUBLIC", "D_PRIVATE", "D_SUBSIDIARY", "D_DIVERSIFY", "ALL_CASH", "ALL_EQUITY"), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame")) – Branko Castro May 11 '17 at 21:01

1 Answers1

9

Your data are in a tibble object. If you convert this object to a data.frame, stargazerworks nicely.

df <- structure(list(D_PUBLIC = c(0, 0, 0, 1, 0, 1), 
                D_PRIVATE = c(1, 1, 1, 0, 0, 0), 
                D_SUBSIDIARY = c(0, 0, 0, 0, 1, 0), 
                D_DIVERSIFY = c(1, 0, 0, 0, 0, 0), 
                ALL_CASH = c(0, 0, 0, 0, 0, 0), 
                ALL_EQUITY = c(1, 0, 1, 1, 0, 0)), 
                .Names = c("D_PUBLIC", "D_PRIVATE", "D_SUBSIDIARY", 
                 "D_DIVERSIFY", "ALL_CASH", "ALL_EQUITY"), 
                 row.names = c(NA, -6L), 
                 class = c("tbl_df", "tbl", "data.frame"))
df

#######################
# A tibble: 6 × 6
  D_PUBLIC D_PRIVATE D_SUBSIDIARY D_DIVERSIFY ALL_CASH ALL_EQUITY
     <dbl>     <dbl>        <dbl>       <dbl>    <dbl>      <dbl>
1        0         1            0           1        0          1
2        0         1            0           0        0          0
3        0         1            0           0        0          1
4        1         0            0           0        0          1
5        0         0            1           0        0          0
6        1         0            0           0        0          0


stargazer(as.data.frame(df), type="text")

=====================================
Statistic    N Mean  St. Dev. Min Max
-------------------------------------
D_PUBLIC     6 0.333  0.516    0   1 
D_PRIVATE    6 0.500  0.548    0   1 
D_SUBSIDIARY 6 0.167  0.408    0   1 
D_DIVERSIFY  6 0.167  0.408    0   1 
ALL_CASH     6 0.000  0.000    0   0 
ALL_EQUITY   6 0.500  0.548    0   1 
-------------------------------------
Marco Sandri
  • 23,289
  • 7
  • 54
  • 58