Odds ratios instead of logits in stargazer() LaTeX output
As per symbiotic comment in 2014, more recent versions of ''stargazer'' have the options ''apply.*'' for ''coef'' ''se'' ''t'' ''p'' and ''ci'' allowing the direct transformation of these statistics.
apply.coef a function that will be applied to the coefficients.apply.se a function that will be applied to the standard errors.apply.t a function that will be applied to the test statistics.apply.p a function that will be applied to the p-values.apply.ci a function that will be applied to the lower and upper bounds of the confidence intervals.
Meaning you can directly use...
stargazer(model, apply.coef = exp, apply.se = exp)
EDIT : I have noticed however that simply exponentiating the CIs does not give what you would expect.
EDIT : You can obtain the correct CIs using the method described here.
stargazer
allows you to substitute a lot of things, dependent variable labels, covariate labels and so forth. To substitute those you need to supply a vector of variable labels, this is done to have publishable row names, instead of variable names from R
by default.
So in order to have odds ratios, you need to supply a vector of odds ratios to stargazer
. How do you obtain that vector? Very easily, actually. Let's say that your model is called model
, then your code is:
coef.vector <- exp(model$coef)stargazer(model,coef=list(coef.vector))
If you have multiple models in your table, then the list should be expanded, e.g. coef=list(coef.vector1,coef.vector2,...)
, where all vectors in the list would be derived from similar exponentiation as above.
So, the issue is that you want to display the (non-log) odds ratio, but keep the test statistics based on the underlying linear model. By default, when you use one of the "apply" methods, such as apply.coef = exp
, stargazer will recalculate the t statistics and p values. We don't want that. Also, the standard errors are in the log basis, but we can't just exponentiate them. My preferred approach is to:
- exponentiate the coefs in stargazer
- turn off the auto p and auto t
- report (untransformed) t-statistics in the table instead of standard errors
In code, this is:
stargazer(model, apply.coef=exp, t.auto=F, p.auto=F, report = "vct*")