Search code examples
rstargazerplm

stargazer output several models R


I run three different estimations of panel linear models (fixed effects model with two fixed effect (id and year)).

fixed_YIELD_mean_to_treat.100 <- plm(YIELD_mean_total ~  treated.100 + Nightlight_sum + Population_sum + temp_mean, data= Results, index = c("id", "year"), model = "within")
fixed_YIELD_mean_fruits_treat.100<- plm(YIELD_mean_Fruit ~  treated.100 + Nightlight_sum + Population_sum + temp_mean, data= Results, index = c("id", "year"), model = "within")
fixed_YIELD_mean_grain_treat.100<- plm(YIELD_mean_Cereal ~  treated.100 + Nightlight_sum + Population_sum + temp_mean, data= Results, index = c("id", "year"), model = "within")

Now I try to create a stargazer output containing all three of the models:

stargazer( fixed_YIELD_mean_to_treat.100, fixed_YIELD_mean_fruits_treat.100, fixed_YIELD_mean_grain_treat.100, 
                   type = "html",
                   align = TRUE,
                   omit = c("year", "id"),
                   omit.labels = c("year FE", "id FE"),
                   add.lines= list(c("ID Fixed effects", "Yes", "Yes", "Yes"),
                                  c("Time Fixed effects", "Yes", "Yes", "Yes")),
                   out = ".test1.html" )

But than I get the error:

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

If I only include 2 models it always works. How can I plot three models in one stargazer output?


Solution

  • As comment says, try to make shorter modelnames:

    library("plm")
    data("Produc", package="plm")
    
    fe1 <- plm(pcap ~ hwy + water + unemp, data=Produc, index=c("state", "year"), model = "within")
    fe2 <- plm(pcap ~ hwy + water + emp, data=Produc, index=c("state", "year"), model = "within")
    fe3 <- plm(pcap ~ hwy + water + pc, data=Produc, index=c("state", "year"), model = "within")
    
    stargazer(fe1, fe2, fe3, type="text")
    
    ================================================================
                                       Dependent variable:          
                              --------------------------------------
                                               pcap                 
                                  (1)          (2)          (3)     
    ----------------------------------------------------------------
    hwy                         2.023***     2.015***     1.999***  
                                (0.052)      (0.050)      (0.051)   
                                                                    
    water                       1.974***     1.989***     1.935***  
                                (0.043)      (0.058)      (0.063)   
                                                                    
    unemp                       -14.624                             
                                (19.682)                            
                                                                    
    emp                                       -0.073                
                                             (0.161)                
                                                                    
    pc                                                     0.003    
                                                          (0.004)   
                                                                    
    ----------------------------------------------------------------
    Observations                  816          816          816     
    R2                           0.901        0.901        0.901    
    Adjusted R2                  0.895        0.895        0.895    
    F Statistic (df = 3; 765) 2,332.767*** 2,331.602*** 2,332.963***
    ================================================================
    Note:                                *p<0.1; **p<0.05; ***p<0.01