I have a dataset containing different stock returns that I want to show in a stargazer table. The problem is that the last row in the dataframe contains NA's in 2 of the 3 columns. Also when I output with stargazer it shows mean, max, min, etc. I only want the actual return value that I have in my dataframe.
Example code:
#Creating dataframe
X <- data.frame("Group" = c("Value", "Growth", "HML"), "Excess of riskfree" = c(0.1, 0.2,NA),
"Excess of Market" = c(0.2,0.4,NA), "Nominal" = c(0.5, 0.6, 0.01))
#Displaying my dataframe
> X
Group Excess.of.riskfree Excess.of.Market Nominal
1 Value 0.1 0.2 0.50
2 Growth 0.2 0.4 0.60
3 HML NA NA 0.01
#Setting up stargazer table
stargazer(X, title="Table 1: Returns", align=T, digits=4, out="Table1_Ret.txt", no.space=T, flip=T)
#This gives the following table
Table 1: Returns
=====================================================
Statistic Excess.of.riskfree Excess.of.Market Nominal
-----------------------------------------------------
N 2 2 3
Mean 0.1500 0.3000 0.3700
St. Dev. 0.0707 0.1414 0.3158
Min 0.1000 0.2000 0.0100
Pctl(25) 0.1250 0.2500 0.2550
Pctl(75) 0.1750 0.3500 0.5500
Max 0.2000 0.4000 0.6000
-----------------------------------------------------
Basically, I want the stargazer table to be somewhat equal to the display of my dataframe in R (Group as Rows and variables as column names). And just display the return values, not the statistical approach which seems to be the default layout.
Doesn't necessarily have to be a table from the stargazer package, if there are other (simpler) solution I would be glad to receive that as well!
All you have to do is add the summary= FALSE option and set the flip option to F:
stargazer(X, summary=F, title="Table 1: Returns", align=T, digits=4, out="Table1_Ret.txt", no.space=T, flip=F)
#Gives you this:
Table 1: Returns
====================================================
Group Excess.of.riskfree Excess.of.Market Nominal
----------------------------------------------------
1 Value 0.1000 0.2000 0.5000
2 Growth 0.2000 0.4000 0.6000
3 HML 0.0100
----------------------------------------------------
Also: stargazer just leaves the NA cells blank. If you want to have it in the table just add it as String:
X <- data.frame("Group" = c("Value", "Growth", "HML"), "Excess of riskfree" = c(0.1, 0.2,"NA"),
"Excess of Market" = c(0.2,0.4,"NA"), "Nominal" = c(0.5, 0.6, 0.01))
#Then you get this:
Table 1: Returns
====================================================
Group Excess.of.riskfree Excess.of.Market Nominal
----------------------------------------------------
1 Value 0.1 0.2 0.5000
2 Growth 0.2 0.4 0.6000
3 HML NA NA 0.0100
----------------------------------------------------
Have a look at the stargazer documentation1 for further layout options.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.