1

I am trying to create a table of regressions using the Stargazer package in R. I have several regressions that differ only in the dummy variables. I want it to report the coefficient of the independent variable, the constant, etc., and to say "yes" or "no" if certain fixed effects (i.e., dummy variables) were included in the regression. These are my regressions:

m1 <- lm(data=merge1,log(total_units)~log(priceIndex))
m2 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code))
m3 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month))
m4 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month)+factor(year))
m5 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month)+time*factor(fips_state_code))
m6 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month)+factor(year)+time*factor(fips_state_code))

I've tried several variations of the stargazer command to get the table to look right, but it never does. When I run this command, for each of the five or six regressions, it works as I expect it to:

stargazer(m2,type="text",
          omit = c("fips_state_code","month","year","time"),
          omit.labels = c("State FE?","Month of year FE?","Year FE?","State time trend?"))

I.e., for m2, it says "Yes" next to "State FE?" and "No" next to all the other questions. For m3, it says "Yes" next to "State FE?" and "Month of year FE?" and "No" next to the other questions.

But when I run this command, the table reports "No" for all of the questions for all of the regressions:

stargazer(m1,m2,m3,m4,m5,m6,type="text",
          omit = c("fips_state_code","month","year","time"),
          omit.labels = c("State FE?","Month of year FE?","Year FE?","Time FE?"))

Does anybody know what is going on? It should work the same whether I do each regression separately or together, no?

I get other weird outcomes too... When I run the following:

stargazer(m3,m4,m5,m6,type="html",
          omit = c("fips_state_code","month","year","time"),
          omit.labels = c("State FE?","Month of year FE?","Year FE?","State time trend?"))

I get this:

<table style="text-align:center"><tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td colspan="4"><em>Dependent variable:</em></td></tr>
<tr><td></td><td colspan="4" style="border-bottom: 1px solid black"></td></tr>
<tr><td style="text-align:left"></td><td colspan="4">log(total_units)</td></tr>
<tr><td style="text-align:left"></td><td>(1)</td><td>(2)</td><td>(3)</td><td>(4)</td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">log(priceIndex)</td><td>2.962<sup>***</sup></td><td>-0.746<sup>***</sup></td><td>0.142</td><td>-1.947<sup>***</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.206)</td><td>(0.249)</td><td>(0.224)</td><td>(0.276)</td></tr>
<tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td></tr>
<tr><td style="text-align:left">Constant</td><td>-0.094</td><td>11.248<sup>***</sup></td><td>8.570<sup>***</sup></td><td>15.030<sup>***</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.652)</td><td>(0.779)</td><td>(0.709)</td><td>(0.868)</td></tr>
<tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">State FE?</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
<tr><td style="text-align:left">Month of year FE?</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
<tr><td style="text-align:left">Year FE?</td><td>No</td><td>No</td><td>No</td><td>No</td></tr>
<tr><td style="text-align:left">State time trend?</td><td>No</td><td>No</td><td>No</td><td>No</td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Observations</td><td>2,853</td><td>2,853</td><td>2,853</td><td>2,853</td></tr>
<tr><td style="text-align:left">R<sup>2</sup></td><td>0.968</td><td>0.974</td><td>0.984</td><td>0.985</td></tr>
<tr><td style="text-align:left">Adjusted R<sup>2</sup></td><td>0.967</td><td>0.974</td><td>0.983</td><td>0.984</td></tr>
<tr><td style="text-align:left">Residual Std. Error</td><td>0.340 (df = 2806)</td><td>0.305 (df = 2800)</td><td>0.244 (df = 2771)</td><td>0.235 (df = 2766)</td></tr>
<tr><td style="text-align:left">F Statistic</td><td>1,830.438<sup>***</sup> (df = 46; 2806)</td><td>2,019.427<sup>***</sup> (df = 52; 2800)</td><td>2,041.885<sup>***</sup> (df = 81; 2771)</td><td>2,084.570<sup>***</sup> (df = 86; 2766)</td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"><em>Note:</em></td><td colspan="4" style="text-align:right"><sup>*</sup>p<0.1; <sup>**</sup>p<0.05; <sup>***</sup>p<0.01</td></tr>
</table>
ejn
  • 415
  • 6
  • 16
  • 1
    Could you consider making your example reproducible by reworking it with use of some accessible data? What do you get through `summary(m1)`? Did you try running `stargazer` without `omit` using [**`all`**](http://www.inside-r.org/packages/cran/stargazer/docs/stargazer_style_list) for `style`? – Konrad Feb 09 '16 at 21:58
  • When I run style="all", the HTML code is way to long for this post. – ejn Feb 09 '16 at 22:04
  • Sorry but without knowing the content of your model results I find it difficult to figure out what is the problem. Broadly speaking the generated table corresponds to what you would get via `stargazer`... – Konrad Feb 09 '16 at 22:10
  • I don't think I can reproduce it using other data. In theory, though, does my code look like it should work? – ejn Feb 09 '16 at 22:10
  • Am I doing this wrong? In the HTML graph that I put up here, it doesn't make sense... You can see in my code above the m4 includes the year dummies. So I'm confused why Stargazer writes "no" in that column. – ejn Feb 09 '16 at 22:12
  • Generally speaking, in terms of layout and presentation it looks fine but I'm guessing that table contents does not correspond to your anticipated outcomes. It would be helpful if you could post a desired results but I'm guessing that without the data it will be difficult to find the solution. Maybe someone more experiences will contribute some ingenious solution... – Konrad Feb 09 '16 at 22:13

1 Answers1

1

Use the add.lines option as described in this this answer.

#load a panel data
data("Wages", package = "plm")

#plain vanilla OLS
model1 <- lm(lwage ~ exp + union + ed + black, data=Wages)
# Least-Squares Dummy Variables model
model2 <- lm(lwage ~ factor(ind) + exp + union + ed + black, data=Wages)

library(stargazer)

stargazer(model1, model2, omit = '[i][n][d]', type='text',
          add.lines=list(c('Fixed effects', 'Yes','No'))
)

=======================================================================
                                    Dependent variable:                
                    ---------------------------------------------------
                                           lwage                       
                               (1)                       (2)           
-----------------------------------------------------------------------
exp                         0.013***                  0.013***         
                             (0.001)                   (0.001)         
                                                                       
unionyes                    0.121***                  0.113***         
                             (0.013)                   (0.013)         
                                                                       
ed                          0.079***                  0.082***         
                             (0.002)                   (0.002)         
                                                                       
blackyes                    -0.269***                 -0.256***        
                             (0.024)                   (0.024)         
                                                                       
Constant                    5.374***                  5.313***         
                             (0.036)                   (0.037)         
                                                                       
-----------------------------------------------------------------------
Fixed effects                  Yes                       No            
Observations                  4,165                     4,165          
R2                            0.283                     0.291          
Adjusted R2                   0.283                     0.290          
Residual Std. Error     0.391 (df = 4160)         0.389 (df = 4159)    
F Statistic         411.209*** (df = 4; 4160) 341.333*** (df = 5; 4159)
=======================================================================
Note:                                       *p<0.1; **p<0.05; ***p<0.01
Marco
  • 2,368
  • 6
  • 22
  • 48