Reference category in the regression table

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?

+7
r latex stargazer
source share
2 answers

Not quite what you wanted, but you can manually specify covariance labels through the covariate.labels argument. I was not able to find out how you could add a headline, though, requiring you to manually add a line.

 stargazer(model1,type='text', covariate.labels=c("Cut (Reference: Fair) Good", ". Very good", ". Premium", ". Ideal")) ====================================================== 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 
+2
source share

This gives close enough to what was desired as an ASCII output. Whether it will be successful in Latex, you will need to test it. Processing \n may not have the same side effects.

 stargazer(model1,type='text', column.labels="\nCut (Reference: Fair)", covariate.labels=c(". Good", ". Very good", ". Premium", ". Ideal")) 

Console:

 ================================================= 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 
+2
source share

All Articles