4

I am computing probit marginal effects from R mfx package. I want to generate Latex code for the marginal effects output. I tried stargazer package for OLS and probit coefficients, it works fine for both, however for probit marginal effects (by using probitmfx command) it doesn't work.

Please help me in this regard, thanks.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Researcher
  • 149
  • 1
  • 8
  • `xtable` and `Hmisc` packages both have facilities to output Latex tables, but you may need to put together the matrix for output by hand. – lmo Feb 22 '17 at 13:51
  • Thanks @Imo, Could you please give a little example, so that i can continue with it. – Researcher Feb 22 '17 at 14:29
  • Just scroll through [these posts](http://stackoverflow.com/questions/tagged/r+xtable). You should find quite a few useful examples. – lmo Feb 22 '17 at 14:48
  • Thank you, i explored all the links but remained unsucceful. – Researcher Feb 23 '17 at 12:44
  • I managed to find the answer here [link] (https://www.r-bloggers.com/porting-stata-like-marginal-effects-to-latex/) – Researcher Jun 11 '17 at 00:30

3 Answers3

2

I haven't found an easy solution, but here is the hack that I use:

ols <- lm(your_formula, data=your_data, family="binomial")
probit <- glm(your_formula, data=your_data, family="binomial")
probit_margins <- probitmfx(your_formula, your_data, atmean=FALSE)$mfxest
your_table <- stargazer(ols, probit, coef = list(NULL, probit_margins[,1]), 
                                     se = list(NULL, probit_margins[,2]))

It works the same with logit, and you don't necessarily want the atmean=FALSE option. I included an OLS in the example to show you how to include other specifications that stargazer can handle, without the need to specify it the coefficients and standard errors.

bixiou
  • 124
  • 2
  • 10
  • And how would you do if you have two probit models and want to include their marginal effects in the table? Thanks! – Esperanta Nov 22 '19 at 16:03
2

Analogous to bixiou's answer, maybe slightly more elegant (at least we don't fit twice):

ols <- lm(your_formula, data=your_data, family="binomial")
probit_margins <- probitmfx(your_formula, your_data, atmean=FALSE)

your_table <- stargazer(ols, probit_margins$fit,
coef = list(NULL, probit_margins$mfxest[,1]),
se = list(NULL, probit_margins$mfxest[,2]))

This exploits the fact that a probitmfx object's fit attribute is the original model.

Pietro Battiston
  • 7,930
  • 3
  • 42
  • 45
0

You can use texreg (documentation):

model <- probitmfx(formula = y ~ x, data = your_data)
texreg(model)
Saurabh Khanna
  • 531
  • 4
  • 4