# losing the variable name after pmap?

Consider this simple example

``````get_reg <- function(...) {
myformula <- paste(..1, ..2)
lm(myformula, data = iris)
}

formulas <- c('~ Sepal.Length ', '~Sepal.Length + Sepal.Width')

list(depvar = 'Petal.Width',
myformula = formulas) %>%
cross_df() %>%
pmap(., ~lm(get_reg(..1, ..2))) %>%
stargazer(type = 'text')
``````

which gives:

``````=====================================================================
Dependent variable:
-------------------------------------------------
..1
(1)                      (2)
---------------------------------------------------------------------
Sepal.Length                0.753***                 0.723***
(0.044)                  (0.039)

Sepal.Width                                         -0.479***
(0.074)

Constant                   -3.200***                -1.563***
(0.257)                  (0.339)

---------------------------------------------------------------------
Observations                  150                      150
R2                           0.669                    0.743
Residual Std. Error     0.440 (df = 148)         0.389 (df = 147)
F Statistic         299.167*** (df = 1; 148) 212.412*** (df = 2; 147)
=====================================================================
Note:                                     *p<0.1; **p<0.05; ***p<0.01
``````

I do not understand why I am losing the dependent variable name. As you can see in the regression table, the dependent variable is the cryptic `..1` instead of `Petal.Width`.

Any ideas? Thanks!

The wrapper I wrote actually works. I just have to call it correctly.

``````list(depvar = 'Petal.Width',
myformula = formulas) %>%
cross_df() %>%
pmap(., ~get_reg(..1, ..2)) %>%
stargazer(type = 'text')
``````

The interesting takeaway is that the formula needs to be computed outside of `lm`, otherwise the dependent variable label gets lost.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.