1

I have just started using the stargazer package in R to automate the creation of tables. I expected that if I create a simple regression model and I feed that into the stargazer package, I should expect to observe the coefficients from the model and the p-values that I obtain from the summary() function.

mod = lm(mtcars$mpg~mtcars$cyl+mtcars$disp)
summary(mod)

Produces:

enter image description here

And then feeding this into stargazer:

stargazer(mod,p.auto = FALSE, 
          align=TRUE, no.space = TRUE, out = "./mtcars.htm", type = 'html')

Produces:

enter image description here

This looks fine. However, what I want is to instead report the standardized coefficients instead of the non-standardized ones. I have used this function "lm.beta" to achieve this:

mod_std = lm.beta(mod)
stargazer(mod_std,p.auto = FALSE, 
          align=TRUE, no.space = TRUE, out = "./mtcars.htm", type = 'html')

Hoping that now stargazer will use the standardized coefficients. The output I get is:

enter image description here

This is strange, because it looks like the significance level changed. Which should not be the case. And still, the unstandardized coefficients are reported. Any ideas on how I could make the package report the standardized coefficients instead?

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

I think your question has already been answered here: Including standardized coefficients in a stargazer table

Stargazer does not automatically know it should look for the standardized coefficients in the second model. lm.beta just add standardzied coefficients to the lm.object. So it is still an lm.object, so it extracts the coefficients as per usual (from model1.beta$coefficients. Use the coef = argument to specify the specific coefficients you want to use: coef = list(mod_std$coefficients, mod_std.beta$standardized.coefficients)

stargazer(mod_std, mod_std.beta, 
            coef = list(mod_std$coefficients, 
            mod_std.beta$standardized.coefficients),
            type='text')
Elias
  • 726
  • 8
  • 20
  • Thanks a lot! One small question: trying this gives me this error: Error in .stargazer.wrap(..., type = type, title = title, style = style, : object 'mod_std.beta' not found. How exactly did you compute this "mod_std.beta" variable? As it is neither the standardized model ("mod_std") nor the original one ("mod")? Or maybe I misunderstood something? – Codrin Mironiuc Apr 19 '22 at 13:27
  • 1
    Just realized that in the syntax you used the example from the previous post. So in my case "mod_std" is "mod" and "mod_std.beta" is "mod_std" :). I have tried it and it works! Something that is still strange - it seems that the significance levels are still different between the standardized and non-standardized coefficients? I thought that they should be preserved across standardization? – Codrin Mironiuc Apr 19 '22 at 13:31
  • 1
    Good to hear that it works :) Regarding the significance level: Are you sure, that you also use the same standard-errors? If yes i would advise posting a question on stat exchange :) – Elias Apr 19 '22 at 14:13
  • 1
    Thanks! I asked this on stat exchange and was informed that if I change the coefficients, the standard errors should also change.. and in this case, stargazer does not seem to also change the standard errors associated with the new, scaled coefficients. Maybe there is a way to further specify that I want to have the standard errors presented in the table corresponding to the new, scaled coefficients? – Codrin Mironiuc Apr 20 '22 at 11:28