I have results from a linear regression model with a factor variable in R, which I would like to get pretty and then output to LaTeX. Ideally, the factor variable will be presented in the table through a row that gives the name of the variable and the reference category, but otherwise it is empty, and then the indented lines below that give the factor levels along with the corresponding estimates.
I have long used the stargazer package to get regression results from R in LaTeX, but I see no way to achieve the result I want with it. Example:
library(ggplot2) library(stargazer) levels(diamonds$cut) options(contrasts = c("contr.treatment", "contr.treatment")) model1 <- lm(price~cut,data=diamonds) stargazer(model1,type='text')
This gives the default output:
=============================================== Dependent variable: --------------------------- price ----------------------------------------------- cutGood -429.893*** (113.849) cutVery Good -376.998*** (105.164) cutPremium 225.500** (104.395) cutIdeal -901.216*** (102.412) Constant 4,358.758*** (98.788) ----------------------------------------------- Observations 53,940 R2 0.013 Adjusted R2 0.013 Residual Std. Error 3,963.847 (df = 53935) F Statistic 175.689*** (df = 4; 53935) =============================================== Note: *p<0.1; **p<0.05; ***p<0.01
Here is what I want:
=============================================== Dependent variable: --------------------------- price ----------------------------------------------- Cut (Reference: Fair) Good -429.893*** (113.849) Very Good -376.998*** (105.164) Premium 225.500** (104.395) Ideal -901.216*** (102.412) Constant 4,358.758*** (98.788) ----------------------------------------------- Observations 53,940 R2 0.013 Adjusted R2 0.013 Residual Std. Error 3,963.847 (df = 53935) F Statistic 175.689*** (df = 4; 53935) =============================================== Note: *p<0.1; **p<0.05; ***p<0.01
Is there a way to achieve this in stargazer without an excessive amount of hackers? Are there other packages in which this would be easier to do?
r latex stargazer
Royalts
source share