# [R] How to create marginal effects tables in R?

Mon Aug 8 17:42:52 CEST 2016

```Hi everyone,

I have three ordered regression models where the ordered dependent variable ranges from 0 to 2. What I want to do is create marginal effects tables (not a plot) at each level (0, 1, and 2) for all three models. So, three tables with each showing the marginal effects at level 0, 1, and 2.

## create a random data that is similar to my dataset
set.seed(987)
mydata <- data.frame(
x1    = sample(c(0, 1, 2), 100, replace = TRUE),
x2    = sample(c(0, 1, 2, 3, 4), 100, replace = TRUE),
x3    = sample(c(0, 1, 2, 3, 5), 100, replace = TRUE),
x4    = sample(c(1:100), 100, replace = TRUE),
x5    = sample(c(10:1000), 100, replace = TRUE),
Y1 = sample(c(0, 1, 2), 100, replace = TRUE)
)

## makeit factor
mydata\$Y1 <- as.factor(mydata\$Y1)

## My models
M1<- polr(Y1 ~x1+x2+x3+x4, data=mydata, Hess = TRUE,  method="logistic")

M2<- polr(Y1 ~x2+x3+x4+x5, data=mydata, Hess = TRUE,  method="logistic")

M3<- polr(Y1 ~x1+x2+x3+x4+x5, data=mydata, Hess = TRUE,  method="logistic")

## Calculate marginal effects using the erer package

M1ME<- ocME(M1)

M2ME <- ocME(M2)

M3ME <- ocME(M3)

Usually I would use the package stargazer to create proper tables, for example:
stargazer(M1,M2, M3, type = ”text”)

However, the output from the OcME()  does not generate the same type of tables and nor can I generate tables at each level. stargazer(M1ME\$out,M2ME\$out, M3ME\$out,  type = "text" )

Do you have any suggestion as to how to generate these types of tables?

[[alternative HTML version deleted]]

```