P_sam
P_sam

Reputation: 13

Stargazer throws error when more than five models used

I am trying to use one of my favorite packages, stargazer, to create a LaTeX table with 7 regression models. This used to work great, but since a recent update (recent on my part, not sure when the original update was done) I get the following error when I try to use more than five models:

Error in if (is.na(s)) { : the condition has length > 1

There are no NA observations, and the models all work when I use them by themselves in stargazer. In fact, any combination of models work until I try and use five simultaneously.

I believe this question has been asked here, but unfortunately the original question did not include a reproduceable example.

Here is my example. The data is a snippet of the SCF and so is public data. Note the problem still exists even if you don't use weighted OLS.

c = structure(list(EQTY_share = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                                  0), MARRIED_pre = c(1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 
                                                      1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 
                                                      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 
                                                      1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1), HHSEX_pre = c(1, 
                                                                                                                              0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 
                                                                                                                              0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 
                                                                                                                              1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 
                                                                                                                              0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1), WGT = structure(c(4930.39000347177, 
                                                                                                                                                                                  4704.28320650246, 3917.62527383248, 4679.17065856539, 4532.8338744778, 
                                                                                                                                                                                  5464.86420532948, 4009.96585980657, 3520.96256713686, 4669.00210194531, 
                                                                                                                                                                                  3794.02574047393, 3587.72518977287, 7367.07278373586, 4588.01315976255, 
                                                                                                                                                                                  4951.76614322902, 5771.82430259193, 3034.97178165389, 6667.74113876358, 
                                                                                                                                                                                  5114.41871363052, 4423.91513876153, 4280.69801738373, 4397.70185006764, 
                                                                                                                                                                                  4202.32384820713, 3916.03065036868, 4904.89146933682, 4058.00537449477, 
                                                                                                                                                                                  3338.502849759, 3051.27717471459, 4343.63230511208, 5742.1802439261, 
                                                                                                                                                                                  4649.67239557703, 3631.54523664957, 4811.86440418757, 5369.22303775956, 
                                                                                                                                                                                  4441.90412465946, 3557.07767919729, 4890.94114408006, 4533.54312102598, 
                                                                                                                                                                                  3984.2155629655, 5340.07854470022, 4970.64563797337, 4787.25645412662, 
                                                                                                                                                                                  3255.88142416359, 3229.53685529925, 5428.68152102248, 4524.95540626004, 
                                                                                                                                                                                  3689.00506972271, 5845.04667795468, 3952.03167801739, 4510.48081497025, 
                                                                                                                                                                                  3012.97658112975, 5503.562879449, 5122.85294981916, 4374.01742982708, 
                                                                                                                                                                                  5025.86608234395, 5097.92377468931, 3519.89950503538, 5229.9081990759, 
                                                                                                                                                                                  7958.45615305438, 4410.38758473807, 4037.32598628441, 4059.69894370641, 
                                                                                                                                                                                  8367.02126269777, 3747.46507881708, 4001.90172707809, 4336.66654844803, 
                                                                                                                                                                                  4962.69416520992, 3335.07507341588, 3497.60482318488, 4875.86681908647, 
                                                                                                                                                                                  6741.09375061725, 6723.7169945403, 2550.48863056955, 4960.45588060922, 
                                                                                                                                                                                  4301.85352631122, 4912.52010780385), label = "X42001: CONSISTENT WGT: REVISED KW", format.stata = "%12.0g")), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                              -75L), class = c("tbl_df", "tbl", "data.frame"))

share_eqty <- lm(data = c,
           weights = WGT,
           formula = EQTY_share ~ MARRIED_pre + HHSEX_pre
           )
#The following generates a LaTeX table
stargazer(share_eqty,share_eqty,share_eqty,share_eqty,share_eqty)

#The following generates the error "Error in if (is.na(s)) { : the condition has length > 1"
stargazer(share_eqty,share_eqty,share_eqty,share_eqty,share_eqty,share_eqty)

Any assistance would be highly appreciated.

This tried checking for NAs, checking each model individually, and using different combinations of the models. I figured none of those were the problem, as it appears also when using the same model more than 5 times. I also tried generating random data and running a regression on that, and in that case the problem does not appear. (Stargazer works as expected for more than 5 models.)

Upvotes: 0

Views: 996

Answers (1)

Nir Graham
Nir Graham

Reputation: 5167

Its clearly a bug in the stargazer internals; stargazer is making an assumtion that the list of input model names its given will fit into one console line it seems. This can be dodged by renaming your model to something shorter. I tried your example and only changed share_eqty to s1 and it worked. I recommend filing a bug report with the stargazer package maintainers

Upvotes: 2

Related Questions